watson使用套接字的文本到语音

如何在使用nodejs在本地主机上运行chatbot时将watson文本转换为语音?

我的chatbot已经运行在本地主机上了。我想将watson文本embedded到语音服务中。 我已经读过,它可以通过websocket接口完成。 我对此没有任何想法

假设您有IBM开发人员使用Node.js和Conversation Service构build的Conversation Simple示例,那么您可以简单地通过使用Websocket按照本教程提交HTTP REST请求,或者您可以使用特定于语言的SDK,粘贴在下面的链接。

所以,几个月前, @ kanebuild立了一个将会话简单的例子与文本结合起来的例子,你可以很容易地在这个链接中find它们。

你可以检查这个提交看到的变化,并按照逻辑在您的应用程序中实现文本到语音。 您将看到上面的代码调用文本到语音服务与.env文件中的服务凭据,如代码中的注释:

const TextToSpeechV1 = require('watson-developer-cloud/text-to-speech/v1'); const textToSpeech = new TextToSpeechV1({ // If unspecified here, the TEXT_TO_SPEECH_USERNAME and // TEXT_TO_SPEECH_PASSWORD env properties will be checked // After that, the SDK will fall back to the bluemix-provided VCAP_SERVICES environment property // username: '<username>', // password: '<password>', }); app.get('/api/synthesize', (req, res, next) => { const transcript = textToSpeech.synthesize(req.query); transcript.on('response', (response) => { if (req.query.download) { if (req.query.accept && req.query.accept === 'audio/wav') { response.headers['content-disposition'] = 'attachment; filename=transcript.wav'; } else { response.headers['content-disposition'] = 'attachment; filename=transcript.ogg'; } } }); transcript.on('error', next); transcript.pipe(res); }); // Return the list of voices app.get('/api/voices', (req, res, next) => { textToSpeech.voices(null, (error, voices) => { if (error) { return next(error); } res.json(voices); }); }); 

Obs .:我build议你看看Commit并按照相同的逻辑在你的应用程序中进行更改。

  • Watson服务的节点SDK 。
  • 通过Node.js使用文本到语音的API参考