4

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:

  • Stream audio from AngularJS directly to Google Cloud Speech API
  • Stream audio from AngularJS to a custom API that relays the feed to Google Cloud Speech API using a client library

Has anyone found a way to stream audio from an AngularJS/HTML5 client to an API like the Google Cloud Speech API?

vt_todd
  • 304
  • 1
  • 5
  • 11

1 Answers1

2

A few options:

  1. 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);
    }
    
  2. Stream server-side using Express and a WebSocket connection or similar configuration in your preferred language.

class
  • 8,621
  • 29
  • 30
  • 1
    I'll give that a try. Strange that the Cloud Speech developer web site (https://cloud.google.com/speech/docs/reference/libraries) doesn't mention the Javascript client library – vt_todd May 10 '17 at 20:20
  • The JavaScript client library is older than the Cloud Client libraries, which are preferred for these APIs - there is not a JavaScript Cloud Client library. – class May 11 '17 at 16:56
  • 1
    What I really needed was a client-side integration with the Natural Language API. That said, your references were helpful and did answer my question. Thanks class. – vt_todd May 16 '17 at 14:25
  • 1
    @vt_todd : Are you able to figure this out? – Triven Jan 20 '18 at 18:35
  • Nope - changed jobs and tech stacks, never came back to it sorry. – vt_todd Jan 21 '18 at 23:34