2

私はWatson Speech To Textサービスを使用して音声認識を実装しようとします。 私は "MediaStreamRecorder"ライブラリを使用してJavaScriptでいくつかのコードを書いています。私はWebsocketを介してデータを送信し、この問題を抱えています。「content-type」:「audio/wav」を使用すると、Watsonは最初のBLOBのみを認識し、inactivity_timeoutをdefaul値に設定します。Watsonは "audio/wav"を認識している間に非アクティブタイムアウトを無視します

私はWebSocketをを開くためにこのコードを使用

initWebSocket(startRecordingCallback) { 
    var that = this; 
    that.websocket = new WebSocket(that.wsURI); 
    that.websocket.onopen = function (evt) { 
     console.log("WebSocket: connection OK "); 
     var message = { 
      "action": "start", 
      "content-type": "audio/wav", 
      "interim_results": true, 
      "continuous": true, 
      "inactivity_timeout": 2 
     }; 
     that.websocket.send(JSON.stringify(message)); 
    }; 
    that.websocket.onclose = function (evt) { 
     if (event.wasClean) { 
      console.log("WebSocket: connection closed clearly " + JSON.stringify(evt)); 

     } else { 
      console.log("WebSocket: disconnect " + JSON.stringify(evt)); 
     } 
    }; 
    that.websocket.onmessage = function (evt) { 
     console.log(evt) 
    }; 
    that.websocket.onerror = function (evt) { 
     console.log("WebSocket: error " + JSON.stringify(evt)); 
    }; 
} 

と音声を記録するため、このコード:

startRecording() { 
    var that = this; 
    this.initWebSocket(function() { 
     var mediaConstraints = { 
      audio: true 
     }; 
     function onMediaSuccess(stream) { 
      that.mediaRecorder = new MediaStreamRecorder(stream); 
      that.mediaRecorder.mimeType = 'audio/wav'; 
      that.mediaRecorder.ondataavailable = function (blob) { 
       that.websocket.send(blob); 
      }; 
      that.mediaRecorder.start(3000); 
     } 

     function onMediaError(e) { 
      console.error('media error', e); 
     } 
     navigator.getUserMedia(mediaConstraints, onMediaSuccess, onMediaError); 
    }); 
} 

私は2秒後にソケットの自動閉鎖とのWebSocketを使用してリアルタイムに認識を行う必要があります不活動の お願いします。

+0

連続した音声の転写には優れたサービスがあります。 –

+0

@NikolayShmyrev、多分、私はワトソンが必要です。 –

+0

完全な例を投稿できると思いますか?また、SDKがあれば簡単にできます:https://github.com/watson-developer-cloud/speech-javascript-sdk –

答えて

0

@Daniel Bolanosはinactivity_timeout秒を超えて転写物が空になると、inactivity_timeoutはトリガーされないと述べています。このサービスは、転写に頼るのではなく、スピーチがあるかどうかを検出するために、別の方法を使用します。

サービスがスピーチを検出すると、トランスクリプトが空であってもinactivity_timeoutがトリガーされません。

ここでは、あなたの質問で何をしようとしていたのですか?speech-javascript-sdkを使用しているコードスニペットです。 将来のStackOverflowユーザーがマイクロフォンからの音声を認識しようとしてくれることを願っています。

document.querySelector('#button').onclick = function() { 
    // you need to provide this endpoint to fetch a watson token 
    fetch('/api/speech-to-text/token') 
    .then(function(response) { 
    return response.text(); 
    }).then(function (token) { 
    var stream = WatsonSpeech.SpeechToText.recognizeMicrophone({ 
     token: token, 
     outputElement: '#output' // CSS selector or DOM Element 
    }); 

    stream.on('error', function(err) { 
     console.log(err); 
    }); 

    document.querySelector('#stop').onclick = function() { 
     stream.stop(); 
    }; 
    }).catch(function(error) { 
    console.log(error); 
    }); 
}; 

デモ:ライブラリを書い@Nathan Friedlyへhttps://watson-speech.mybluemix.net/microphone-streaming.html

クレジット。

関連する問題