[英]How to pipe Watson speech using the Text-to-Speech service to the browser
I have an express application and I added this snippet of code: 我有一个快速应用程序,并添加了以下代码片段:
var TextToSpeechV1 = require('watson-developer-cloud/text-to-speech/v1');
var fs = require('fs');
var text_to_speech = new TextToSpeechV1({
username: '<username>', (added username and password)
password: '<password>'
});
var params = {
text: 'Hello from IBM Watson',
voice: 'en-US_AllisonVoice', // Optional voice
accept: 'audio/wav'
};
// Pipe the synthesized text to a file
text_to_speech.synthesize(params).pipe(fs.createWriteStream('output.wav'));
After running the node app
command, a ouput.wav
was generated in my file. 运行
node app
命令后,在我的文件中生成了ouput.wav
。 It worked as expected and said "Hello from IBM Watson." 它按预期工作,并说“ IBM Watson向您问好”。 But I want this to be outputted to the browser, like when someone presses a tag.
但是我希望将其输出到浏览器,就像有人按下标签一样。 How do I go from here?
我怎么从这里走?
The Text to Speech demo does what you want and it's on GitHub . 文本语音转换演示可以满足您的要求,并且在GitHub上 。 It streams the audio back to the Browser which uses an
<audio>
HTML tag to reproduce it. 它将音频流传输回浏览器,该浏览器使用
<audio>
HTML标签对其进行再现。
If yo useparate your application in Client and Server you will need: 如果您要在客户端和服务器中使用您的应用程序,则需要:
An <audio>
element with the src
pointing to an endpoint that synthesizes the text, something like: https://<host>/api/synthesize?text=This+is+a+test
一个
<audio>
元素,其src
指向合成文本的端点,例如: https://<host>/api/synthesize?text=This+is+a+test
Assuming you use Express and based on your code above
假设您使用Express并基于上面的代码
app.get('/api/synthesize', function(req, res, next) {
var transcript = text_to_speech.synthesize(req.query);
transcript.on('error', next);
transcript.pipe(res);
});
The audio will be pipe to the browser which will play it as it comes from the service. 音频将通过管道传输到浏览器,并从服务中播放。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.