1
votes

I want to implement the Google Cloud speech to text using a service account. What i have try is i have set the environment variable to that json and send the post request to this url 'https://speech.googleapis.com/v1/speech:longrunningrecognize'.

Code: req = requests.post(url, data={ "audio":{ "content":enc }, "config":{ "audioChannelCount":2, "enableSeparateRecognitionPerChannel":True, "enableWordTimeOffsets":True, "diarizationConfig":{ "enableSpeakerDiarization": True, "minSpeakerCount": 1, "maxSpeakerCount": 2 },

}}) Error: 403 { "error": { "code": 403, "message": "The request is missing a valid API key.", "status": "PERMISSION_DENIED" } }

1
You are missing the HTTP Authorization: Bearer [TOKEN] header. Just setting the environment variable does not do this. Tip: Format your question so that people can read your code and error messages. In this article look at the code for listing instances. Very similar to what you need to do for your POST request. jhanley.com/…John Hanley

1 Answers

1
votes

The error message indicates that you are not authenticating correctly. The way to do this is to pass an authentication token as a Bearer Token header in your request.

The following documentation explains how to generate the required credentials and pass them with the request, this provides an overview of service accounts Service accounts overview

Creating a service account instructions Creating service accounts

Once you have created the service account you generate the credentials which are stored in json format, these are then passed as a Bearer Token