First, make sure that you have Node.js installed on your computer. If you don’t, download it from here. Then, run the following commands one by one in your Terminal to set up the working environment:
npm install express npm install ws npm install @google-cloud/speech
And when it’s done, create an empty JS file and put the following code in there (learn the code nuances below):
Now that we have the server all set up, it'll help us achieve our speech recognition goals. Test your solution locally by making a tunnel to your localhost 3000 with the help of ngrok.
To do that, follow these steps:
- Install ngrok following the instructions on its site.
- Specify your authtoken to ngrok so that your client is tied to this account.
node your_file_name.jsto start your server locally on localhost:3000.
- Go to the ngrok folder on your computer and run
./ngrok http 3000to tunnel your running local server to a public URL.
Pay attention to the generated public URL, we use it as the WebSocket URL with the 'wss' prefix in our scenario: