私は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を使用してリアルタイムに認識を行う必要があります不活動の お願いします。
連続した音声の転写には優れたサービスがあります。 –
@NikolayShmyrev、多分、私はワトソンが必要です。 –
完全な例を投稿できると思いますか?また、SDKがあれば簡単にできます:https://github.com/watson-developer-cloud/speech-javascript-sdk –