Rate this page:

4. Speech recognition

You’ve probably noticed that our backend code contains some lines related to Google Cloud.

The library itself is imported this way:

Import the library

Import the library

Now you need to specify how to process the request. To do that, choose an encoding, sampleRateHertz, and languageCode in the config:

Set parameters

Set parameters

Then, create a new stream to be written into a binary file:

Create a stream

Create a stream

When everything is set up, you should parse the message and put base64 audio data to recognizeStream:

Put base64 audio to recognizeStream

Put base64 audio to recognizeStream

Right after this, a recognition request will be initiated and therefore handled:

Initiate and handle the recognition request

Initiate and handle the recognition request

Lastly, obtain and provide your service account credentials to connect the Google library to its backend. To do this, go to the Google Authentication page and complete all the steps listed there. Next, run this export command in the same workspace (the same Terminal tab) as the node your_file_name.js:

export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/[FILE_NAME].json"