2017-09-08 17 views
0

メソッドstream.onstream.recognizeStream.onのドキュメントが見つかりません。 documentationAPIを検索しました。この時点で私の具体的な質問が約束についてです、例えば、これは動作しません:IBM Watson Speech-to-textの「ストリーム」とは何ですか?

stream.on('data', function(transcribedSpeech) { 
    console.log(transcribedSpeech); 
}) 
.then(function() { 
    console.log("Then..."); 
    this.transcribedSpeech = transcribedSpeech; 
}) 
.catch(function() { 
    console.log("Error"); 
}); 

エラーがTypeError: stream.on(...).then is not a functionです。 IBM Watson Speech-to-textのAngularjsサービスを作成しようとしています。すべてが機能しています。つまり、Watsonのメッセージ、トランスクリプト、キーワードなどは、サービスからコントローラにデータストリームを取得できないことを除いてコンソールにログしています。コントローラからサービスを呼び出すと、コントローラはパラメータの初期値(undefined)のみを認識し、ワトソンがデータストリームの送信を開始した後は値を参照しません。私は約束がこれを修正することを期待していたが、運はない。 :-(

答えて

0

私はテキストにスピーチで1人の専門家ではないんだけど、私はAPIリファレンスおよびIBMによるプロジェクトを使用して数ヶ月前に一例をしました。

あなたが見ることができるように、次の例は、 APIリファレンスに使用される、recognizeStreamは、テキストにスピーチのインスタンスに使用され、あなたが送っスピーチ、createRecognizeStreamfunctionNode SDKを認識用される。

あなたは他の変数を使用することができ、あなたの依存、しかし、あなたが必要ですテキストをスピーチにインスタンス化し、スピーチのイベントを認識するためにcreateRecogniseStreamを呼び出す。

サービスは、次の例のように、UTF8に設定した後、あなたのファイルを転写産物とテキストが認識トランスクリプトファイルを追加します:

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

var speech_to_text = new SpeechToTextV1 ({ 
    username: '{username}', 
    password: '{password}' 
}); 

var params = { 
    model: 'en-US_BroadbandModel', 
    content_type: 'audio/flac', 
    'interim_results': true, 
    'max_alternatives': 3, 
    'word_confidence': false, 
    timestamps: false, 
    keywords: ['colorado', 'tornado', 'tornadoes'], 
    'keywords_threshold': 0.5 
}; 

// Create the stream with the instancie of speech to text and access the function to Recognise the speech. 
var recognizeStream = speech_to_text.createRecognizeStream(params); 

// Pipe in the audio in the parameter recognizeStream. 
fs.createReadStream('audio-file.flac').pipe(recognizeStream); 

// Pipe out the transcription to a file. 
recognizeStream.pipe(fs.createWriteStream('transcription.txt')); 

// Get strings instead of buffers from 'data' events. 
recognizeStream.setEncoding('utf8'); 

// Listen for events using the paramter after set utf8 and the transcrit file. 
recognizeStream.on('results', function(event) { onEvent('Results:', event); }); 
recognizeStream.on('data', function(event) { onEvent('Data:', event); }); 
recognizeStream.on('error', function(event) { onEvent('Error:', event); }); 
recognizeStream.on('close', function(event) { onEvent('Close:', event); }); 
recognizeStream.on('speaker_labels', function(event) { onEvent('Speaker_Labels:', event); }); 

// Displays events on the console. 
function onEvent(name, event) { 
    console.log(name, JSON.stringify(event, null, 2)); 
}; 
  • は、Node.jsの
  • と音声をテキストに使用して Officialリファレンスを参照してください。
  • ProjectスピーチからテキストおよびNode.jsを使用するIBM開発者による
関連する問題