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 ...