0
votes

I have created Google Storage bucket to perform Google Speech-to-text for the audio file in the bucket. But this is not working as the bucket is denying access to the Google Speech API.

Error Message: Anonymous caller does not have storage.objects.get access PERMISSION_DENIED

Speech uses API key for authentication and Storage uses service account key for authentication. I have already given access to the service account in bucket permission.

Is it possible to give Speech access to storage bucket?

I also tried giving bucket permission to service account. But it does not work.

1
Where are you calling the API from? Are you calling it from a resource within Google Cloud?ScottMcC
I am calling the API from my local machine. As @asbovelw mentioned, I was missing the access token for authorization in Speech API request header. After adding the service account's access token I was able to access the bucket. curl -X POST \ speech.googleapis.com/v1/speech:longrunningrecognize \ -H 'authorization: Bearer <access_token>' \ -d '{ '\''audio'\'': { '\''uri'\'':<storage_uri>' }, '\''config'\'': { '\''languageCode'\'': '\''en-US'\'' } }'Lavenya

1 Answers

0
votes

You are not using authentication at all; this is shown by "Anonymous caller" in the error message.

It seems you are directly accessing the API, either with curl or another tool.

In order to authenticate this way, you can follow these instructions. Look at the curl examples but do it like this (using gcloud auth print-access-token as an easy way to generate the access token from the CLI), substituting "$BUCKET_NAME" with your bucket's name and "$OBJECT_NAME" with your object's name (with environment variables or literally):

curl -H "Authorization: Bearer $(gcloud auth print-access-token)" -i "https://www.googleapis.com/download/storage/v1/b/$BUCKET_NAME/o/$OBJECT_NAME?alt=media"

Be careful, though, as this downloads the file to your terminal and can mess with its display. To avoid this, just append a "> $OBJECT_NAME" to the command to save the requested file.