1
如何在使用nodejs在本地主机上运行chatbot时将watson文本转换为语音?watson使用套接字的文本到语音
我的聊天机器人已经在本地主机上运行了。我想将watson文本嵌入到语音服务中。我已经读过它可以通过websocket接口完成。我对此没有任何想法
如何在使用nodejs在本地主机上运行chatbot时将watson文本转换为语音?watson使用套接字的文本到语音
我的聊天机器人已经在本地主机上运行了。我想将watson文本嵌入到语音服务中。我已经读过它可以通过websocket接口完成。我对此没有任何想法
假设您有IBM开发人员使用Node.js和Conversation Service构建的对话简单示例,您可以简单地让您的应用程序通过使用Websocket跟随此tutorial或您可以利用特定于语言的SDK,我将粘贴到下面的链接中。
因此,几个月前@kane就建立了一个将会话简单的例子与文本到语音相结合的例子,您可以在link中轻松找到它们。
您可以检查这个commit看到的变化,并按照逻辑在您的应用程序中实现文本到语音。你会看到上面打电话文本到语音服务,在.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);
});
});
实验值:我建议你看Commit
和按照相同的逻辑在您的应用中进行更改。
你需要什么编程语言呢? –
我想使用nodejs – sajeet