【发布时间】:2018-12-03 21:33:14
【问题描述】:
我有以下代码,直接来自文档:
var TextToSpeechV1 = require('watson-developer-cloud/text-to-
speech/v1');
var fs = require('fs');
var textToSpeech = new TextToSpeechV1({
iam_apikey: '---myapikey---',
url: 'https://stream.watsonplatform.net/text-to-speech/api/'
});
var synthesizeParams = {
text: 'Hello world, you dummy ass',
accept: 'audio/wav',
voice: 'en-US_AllisonVoice'
};
// Pipe the synthesized text to a file.
textToSpeech.synthesize(synthesizeParams).on('error', function(error) {
console.log(error);
}).pipe(fs.createWriteStream('hello_world.wav'));
当我运行它时,它会给出以下错误:
pi@raspberrypi:~/Desktop/tjbotcz_lite $ sudo node ttstest.js
/home/pi/Desktop/tjbotcz_lite/ttstest.js:16
textToSpeech.synthesize(synthesizeParams).on('error', function(error) {
^
TypeError: Cannot read property 'on' of undefined
at Object.<anonymous> (/home/pi/Desktop/tjbotcz_lite/ttstest.js:16:42)
at Module._compile (internal/modules/cjs/loader.js:654:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
at Module.load (internal/modules/cjs/loader.js:566:32)
at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
at Function.Module._load (internal/modules/cjs/loader.js:498:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
at startup (internal/bootstrap/node.js:201:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)
任何线索为什么?我对 TJBot 也有同样的问题,所以我从文档中尝试了一个简单的例子,瞧——同样的错误。 当我使用旧服务(使用用户名和密码,而不是 api 密钥)时,它工作正常。我有新版本的 watson-cloud 库 (3.13.1)。
感谢您的任何提示。 问候, 一月。
【问题讨论】: