Google Cloud Speech-to-Text API key error
I tried to use the Google Cloud Speech-to-Text API but without any success. I have an API key error.
Here is my api call :
curl -s -H "Content-Type: application/json" \
-H "Authorization: Bearer "$(myapikey) \
https://speech.googleapis.com/v1/speech:recognize \
-d @sync-request.json
sync-request.json content is the following :
{
"config": {
"encoding":"FLAC",
"sampleRateHertz": 48000,
"languageCode": "fr-FR",
"enableWordTimeOffsets": true
},
"audio": {
"uri":"gs://audio-bucket_bl/audio.flac"
}
}
and result is the following :
-bash: myapikey: command not found
{
"error": {
"code": 403,
"message": "The request is missing a valid API key.",
"status": "PERMISSION_DENIED"
}
}
For your information, I took my api key from here : https://console.cloud.google.com/apis/credentials? (Key 1 from api keys list)
Do you know what I'm doing wrong ? It's about the api key so or it's the wrong one or I do not set it in the good way.
Thank you for your help :)
Best regards,
Solution 1:
In your command this construct
$(myapikey)
tells the shell to run the command myapikey, the output from which would be substituted in it's place e.g.
ls $(which chmod) -l
-rwxr-xr-x. 1 root root 58592 Aug 20 2019 /bin/chmod
This explains why you see this error
-bash: myapikey: command not found
as there is no command myapikey
(in your path). You do not need to use the $(...)
, using
"$myapikey"
will probably work as you expect.