尝试使用Watson语音到文本API时出现“ speech_to_text.createRecognizeStream不是函数”错误

时间:2019-11-09 03:02:18

标签: ibm-watson

我正在尝试使用Watson语音使用Node编写文本API。当我尝试运行代码时,将显示此错误:

recognizeStream = speech_to_text.createRecognizeStream(params);
                                 ^
TypeError: speech_to_text.createRecognizeStream is not a function

我是一个新手,所以我可能会错过一些非常基本的内容。

var mic;
var SpeechToTextV1 = require('watson-developer-cloud/speech-to-text/v1');
var fs = require('fs');
// var watson = require('ibm-watson');
var cp = require('child_process');
mic = cp.spawn('arecord', ['--device=plughw:1,0', '--format=S16_LE', '--rate=44100', '--channels=1']); //, '--duration=10'
mic.stderr.pipe(process.stderr);
stt();

function stt() {
  console.log("openCMDS");
  var speech_to_text = new SpeechToTextV1({
  username: 'apikey',
  password: 'j9SvIjQpREewJkanbpQunN-McXWEjRNFTI87Vrvicr_I'
});
var params = {
  content_type: 'audio/wav',
  model: 'zh-CN_BroadbandModel',
  continuous: true,
  inactivity_timeout: -1
};
recognizeStream = speech_to_text.createRecognizeStream(params);
mic.stdout.pipe(recognizeStream);
// Pipe in the audio.
fs.createReadStream('test.wav').pipe(recognizeStream);
recognizeStream.pipe(fs.createWriteStream('transcription.txt'));
recognizeStream.setEncoding('utf8'); 
console.log("start record");
recognizeStream.on('data', function(event) { onEvent('Data:', event); });
recognizeStream.on('error', function(event) { onEvent('Error:', event); });
recognizeStream.on('close', function(event) { onEvent('Close:', event); });

// Display events on the console.
function onEvent(name, event) {
  console.log(name, JSON.stringify(event, null, 2)); }}

0 个答案:

没有答案