Search code examples
google-speech-api

Google speech api error


When I run the simple command on my linux machine:

curl -X POST \
--data-binary @'1.wav' \
--header 'Content-Type: audio/l16; rate=16000;' \
'https://www.google.com/speech-api/v2/recognize?output=json&lang=he-IL&key=THE_KEY'

I am getting the error:

Your client does not have permission to get URL /speech-api/v2/recognize?output=json&lang=he-IL&key=THE_KEY from this server. Invalid key. That’s all we know.

The key that I have generated has no restrictions (and it was enabled for the speech api).
I even added the server ip address and i got the same error.

The results I found so far are related to the chrome client... Im on shell.

Thanks


Solution

    1. Create a JSON request file with the following text, and save it as a sync-request.json plain text file:

      { 'config': { 'encoding':'FLAC', 'sampleRate': 16000, 'languageCode': 'en-US' }, 'audio': { 'uri':'gs://your-gcloud-bucket/audio.wav' } }

      This JSON snippet indicates that the audio file has a WAV encoding format, a sample rate of 16000 Hz, and that the audio file is stored on Google Cloud Storage at the given URI. The audio file is publicly accessible, so you will not need authentication credentials to access the file (though you will need authentication credentials to use the API).

    2. Authenticate to your service account, passing the location of your service account key file:

      $ gcloud auth activate-service-account --key-file=service-account-key-file

    3. Obtain an authorizaton token using your service account:

      $ gcloud auth print-access-token access_token

    4. Use curl to make a speech:syncrecognize request, passing it the access token you printed, and the filename of the JSON request you set up in step 1:

      $ curl -s -k -H "Content-Type: application/json" \ -H "Authorization: Bearer access_token" \ https://speech.googleapis.com/v1beta1/speech:syncrecognize \ -d @sync-request.json