Reputation: 304
I am new to the HTML5 Web Audio API and to Google Cloud Speech API. I am trying to build speech-recognition into an AngularJS application so the user can perform a search using speech-to-text instead of typing into a search with the keyboard.
The intent is to use getUserMedia() to capture and stream audio from the client to the Google Cloud Speech API, and asynchronously recieve back results.
Google offers a set of client libraries that allow you to stream from server-side platforms like C#, Node and Java to their API but I can't find an example showing how I can do either of the following:
Has anyone found a way to stream audio from an AngularJS/HTML5 client to an API like the Google Cloud Speech API?
Upvotes: 4
Views: 2919
Reputation: 8681
A few options:
Stream client-side sample code:
function sendBytesToSpeech (bytes, encoding, rate, callback) {
gapi.client.speech.speech.syncrecognize({
config: {
encoding: encoding,
sampleRate: rate
},
audio: {
content: bytes
}
}).execute(function (r) {
callback(r);
});
}
function sendBlobToSpeech (blob, encoding, rate) {
var speechSender = new FileReader();
speechSender.addEventListener('loadend', function () {
sendBytesToSpeech(btoa(speechSender.result), encoding, rate, uiCallback);
});
speechSender.readAsBinaryString(blob);
}
Stream server-side using Express and a WebSocket connection or similar configuration in your preferred language.
Upvotes: 2