Google Speech API'sine bir web bağlantısı bağlantısının ses akışını göndermeye çalışıyorum. Websocket, ikili mesajları 20 ms'lik artışlarla gönderir. Bunu artışlarla göndermek, bir şekilde Google'a olan bağlantıyı öldürmekten kaçınmak için verileri yerel bir dosyaya geçici olarak okuyup yazmam gerektiğine inanmamı sağlıyor. Ancak, bu ideal değildir.Google Speech API'ye websocket ikili mesajlarını akış olarak nasıl gönderilir?
Websocket akışını doğrudan recognizeStream
içine sokmanın bir yolu var mı? dokümanlardan
tarihinde streamingRecognize örnek:
const request = {
config: {
encoding: encoding,
sampleRate: sampleRate
}
};
const recognizeStream = speech.createRecognizeStream(request)
.on('error', console.error)
.on('data', (data) => process.stdout.write(data.results));
record.start({
sampleRate: sampleRate,
threshold: 0
}).pipe(recognizeStream);
WebSocket'e bağlantısı:
var HttpDispatcher = require('httpdispatcher');
var dispatcher = new HttpDispatcher();
var WebSocketServer = require('websocket').server;
var server = http.createServer(handleRequest);
var wsServer = new WebSocketServer({
httpServer: server,
autoAcceptConnections: true,
});
function handleRequest(request, response){
try {
//log the request on console
console.log(request.url);
//Dispatch
dispatcher.dispatch(request, response);
} catch(err) {
console.log(err);
}
}
wsServer.on('connect', function(connection) {
console.log((new Date()) + ' Connection accepted' + ' - Protocol Version ' + connection.webSocketVersion);
connection.on('message', function(message) {
if (message.type === 'utf8') {
console.log(message.utf8Data);
}
else if (message.type === 'binary') {
//Send to Google Speech API by passing into recognizeStream
}
});
connection.on('close', function(reasonCode, description) {
console.log((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected.');
});
});