1

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" } }

Kunfu Panda
  • 57
  • 1
  • 2
  • 8
  • 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. https://www.jhanley.com/google-cloud-creating-oauth-access-tokens-for-rest-api-calls/ – John Hanley Dec 05 '19 at 05:45

2 Answers2

0

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

Paddy Popeye
  • 1,634
  • 1
  • 16
  • 29
  • 2
    after reading both articles in your link I'm almost 100% certain that there is no information about how to pass credential with the request in your first link and no related information about this error in your second link. I'm not trying to create or manage service account, I want to use one directly with samples provided in your git and it fails. – AaA Aug 26 '21 at 11:57
0

Send your Google API key in the URL with get method: <https://google-api-url>?key=<YourGoogleApiKey>

I tried this to speech-to-text feature and it worked like this

jayg_code
  • 571
  • 8
  • 21
MZp3rY
  • 1