0

IBM の音声テキスト変換サービスの Websocket 実装を使用しようとしています。現在、接続を介して .wav ファイルを送信する方法がわかりません。それをブロブに変換する必要があることはわかっていますが、その方法がわかりません。現在、次のエラーが発生しています。

You must pass a Node Buffer object to WebSocketConnec

-また-

Could not read a WAV header from a stream of 0 bytes

...サービスに渡そうとするものによって異なります。なお、正しく開始メッセージを送信し、リッスン状態にしています。

4

1 に答える 1

1

v1.0 (まだベータ版) 以降、watson-developer-cloud npm モジュールは Websockets をサポートしています。

npm install watson-developer-cloud@1.0.0-beta.2

wav ファイルを認識します。

var watson = require('watson-developer-cloud');
var fs = require('fs');

var speech_to_text = watson.speech_to_text({
  username: 'INSERT YOUR USERNAME FOR THE SERVICE HERE',
  password: 'INSERT YOUR PASSWORD FOR THE SERVICE HERE',
  version: 'v1',
});


// create the stream
var recognizeStream = speech_to_text.createRecognizeStream({ content_type: 'audio/wav' });

// pipe in some audio
fs.createReadStream('audio-to-recognize.wav').pipe(recognizeStream);

// and pipe out the transcription
recognizeStream.pipe(fs.createWriteStream('transcription.txt'));


// listen for 'data' events for just the final text
// listen for 'results' events to get the raw JSON with interim results, timings, etc.

recognizeStream.setEncoding('utf8'); // to get strings instead of Buffers from `data` events

['data', 'results', 'error', 'connection-close'].forEach(function(eventName) {
  recognizeStream.on(eventName, console.log.bind(console, eventName + ' event: '));
});

ここで他の例を参照してください。

于 2015-11-05T04:39:59.820 に答える