【问题标题】:How to pipe Watson speech using the Text-to-Speech service to the browser如何使用 Text-to-Speech 服务将 Watson 语音传输到浏览器
【发布时间】:2016-08-26 16:19:17
【问题描述】:

我有一个 express 应用程序,我添加了这个 sn-p 代码:

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'));

运行node app 命令后,在我的文件中生成了一个ouput.wav。它按预期工作,并说“来自 IBM Watson 的你好”。但我希望将其输出到浏览器,就像有人按下标签时一样。从这里怎么走?

【问题讨论】:

  • 将 .wav 塞入您网站的文档根目录中,然后简单地将客户端 &lt;audio&gt; 标记指向它?

标签: ibm-cloud text-to-speech ibm-watson


【解决方案1】:

文字转语音demo 可以满足您的需求,并且位于GitHub 上。它将音频流回浏览器,浏览器使用&lt;audio&gt; HTML 标签来重现它。

如果您在客户端和服务器中使用分离您的应用程序,您将需要:

客户

带有src&lt;audio&gt; 元素指向合成文本的端点,例如:https://&lt;host&gt;/api/synthesize?text=This+is+a+test

服务器

假设您使用 Express 并基于您上面的代码

app.get('/api/synthesize', function(req, res, next) {
  var transcript = text_to_speech.synthesize(req.query);
  transcript.on('error', next);
  transcript.pipe(res);
});

音频将通过管道传输到浏览器,浏览器将在它来自服务时播放它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-01
    • 2019-05-11
    相关资源
    最近更新 更多