Я решил эту проблему в приложении Node.js, создав серию запросов на потоковое распознавание.
Код находится здесь: https://github.com/marciovm/Speech-Forever.
Хитрость заключается в том, чтобы запрашивать новые потоки на стороне клиента (из браузера пользователя или его эквивалента) в подходящий перерыв во входной речи.
Ключевой раздел на app.js (сервер Node)
var gstreams = []; // keeep track of speech streams
var activeStreamID = -1; // pointer to active speech stream
ws.on('message', function (data) {
if ( typeof data == 'string' ) {
if (data.indexOf("info")>0) { // client sends an info string on connection that triggers server to start a speech stream
console.log('Start first stream');
gstreams.push(startGoogleSpeechStream(ws));
activeStreamID = activeStreamID + 1;
}
else { // client requested a new speech stream (client-side logic allows for triggering on a lull in input volume)
console.log('Start another stream');
gstreams[activeStreamID].end();
gstreams.push(startGoogleSpeechStream(ws));
activeStreamID = activeStreamID + 1;
}
}
else {
gstreams[activeStreamID].write(data); // client sent audio, push it to active speech stream
}
});
Ключевой раздел на demo.js (клиентский браузер)
var handleSuccess = function(stream) {
setRecordingTrue(1000); // give socket 1 sec to open
audioInput = context.createMediaStreamSource(stream);
audioInput.connect(recorder);
recorder.onaudioprocess = function(stream){
if(!recording) return;
var buf = stream.inputBuffer.getChannelData(0);
volume = detectVolume(buf, this);
$(".volume_meter")[0].value=volume * 100;
if (volume < 0.01 && (Date.now() > (streamStartTime + breakTime))) {
ws.send("restarting Google Stream");
console.log("restarting Google Stream");
streamStartTime = Date.now();
writeToCaret(' ');
}
else {
ws.send(float32ToInt16(buf)); // send audio stream to Node server
}
}
}
person
marciovm
schedule
30.10.2017