简体   繁体   English

如何使用Text-to-Speech服务将Watson语音通过管道传输到浏览器

[英]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: 如果您要在客户端和服务器中使用您的应用程序,则需要:

Client 客户

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

Server 服务器

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.

相关问题 Bluemix中的Watson Text-to-Speech服务是否适用于移动应用程序? - Does the Watson Text-to-Speech service in Bluemix work for mobile apps? 如何在 node.js 中使用 Watson text-to-speech api? - How to use Watson text-to-speech api in node.js? 如何停止IBM Watson文本转语音的StreamPlayer - How to stop StreamPlayer of IBM Watson text-to-speech 如何将 watson 对话与 Speech-to-text 和 text-to-speech API 集成 - how to integrate watson conversation with Speech-to-text and text-to-speech APIs 如何使用 javascript 在浏览器中运行 IBM Watson 文本转语音 - How to run IBM Watson Text to speech in browser using javascript 使用 CURL 无法将任何 SSML 标记应用于 IBM Watson 的文本到语音系统中的文本 - Unable to apply any SSML tag to the text in IBM Watson's text-to-speech system, using CURL IBM Watson Text-to-Speech 问题与德语变音 (ä-ö-ü) - IBM Watson Text-to-Speech issue with German umlaute (ä-ö-ü) IBM Watson文本到语音的卷曲示例不起作用 - IBM Watson text-to-speech curl example not working 如何在 android 中集成 Bluemix 服务对话、语音到文本和文本到语音 - How can I integrate Bluemix service Conversation, Speech-To-Text and Text-To-Speech in android 通过WebSocket在浏览器中使用Watson Speech to Text(实时检测) - Using watson Speech to Text from a browser with websockets (Live detection)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM