IBM Watson TextToSpeech - не может прочитать свойство .pipe неопределенного - PullRequest
0 голосов
/ 04 декабря 2018

У меня есть следующий код, прямо из документации:

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).

Спасибо за любые подсказки.С уважением, январь.

1 Ответ

0 голосов
/ 04 декабря 2018

Приведенный ниже код работает для меня и создает файл audio.wav с использованием API-интерфейса Text-to-Speech *

var TextToSpeechV1 = require('watson-developer-cloud/text-to-speech/v1');
var fs = require('fs');

var textToSpeech = new TextToSpeechV1({
  iam_apikey: '<API_KEY>',
  url: 'https://stream.watsonplatform.net/text-to-speech/api'
});

var synthesizeParams = {
  text: 'Hello world',
  accept: 'audio/wav',
  voice: 'en-US_AllisonVoice'
};

textToSpeech
  .synthesize(synthesizeParams, function(err, audio) {
    if (err) {
      console.log(err);
      return;
    }
    textToSpeech.repairWavHeader(audio);
    fs.writeFileSync('audio.wav', audio);
    console.log('audio.wav written with a corrected wav header');
});

Обновлен фрагмент кодаи это работает

...