Updating the controller

Now that are done with defining the routes and updating the model, we will work on the logic as discussed in the Solution design section earlier. We are going to add a new method to CloudAIAPI named uploadAudio. Open server/controllers/cloud-ai-api.ts and we will first add the required imports, and SpeechClientconfiguration. Before the class definition, add this code:

// SNIPP SNIPPconst speech = require('@google-cloud/speech');const speechClient = new speech.SpeechClient({    credentials: JSON.parse(process.env.GCP_SK_CREDENTIALS)});// SNIPP SNIPP

Using the environment variable we set in the .env file, we are using the GCP_SK_CREDENTIALS value to initialize a new SpeechClient. Next, we are going to create a new method ...

Get Google Cloud AI Services Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.