I'm testing out the Google Cloud Speech API command-line on Raspberry Pi 3 Raspbian OS using the gcloud SDK. The standard procedure Google provides worked on my Mac OSX! Attempting it in Raspbian fails.
I tried setting ENV vars like "GOOGLE_APPLICATION_CREDENTIALS" and "GCLOUD_PROJECT", and when that didn't work, I unset those vars and tried running "gcloud beta init" instead of "gcloud init". No combination of these works.
Command:
curl -v -k -s -H "Content-Type: application/json" -H "Authorization: Bearer `gcloud auth print-access-token`" "https://speech.googleapis.com/v1beta1/speech:syncrecognize" -d @sync-request.json
(note: for the contents of 'sync-request.json', please see the quickstart guide example).
The error message I'm getting is shown below. It seems the wrong project gets is getting selected:
OUTPUT:
{
"error": {
"code": 403,
"message": "Google Cloud Speech API has not been used in project google.com:cloudsdktool before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/speech.googleapis.com/overview?project=google.com:cloudsdktool then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
"status": "PERMISSION_DENIED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"description": "Google developers console API activation",
"url": "https://console.developers.google.com/apis/api/speech.googleapis.com/overview?project=google.com:cloudsdktool"
}
]
}
]
}
}
Solved the auth issue by specifying "application-default" whenever running "gcloud auth" commands (that means for both login and when printing the access token)
First run:
gcloud auth application-default login
*** or you can set the "GOOGLE_APPLICATION_CREDENTIALS" env var instead for your service account's private_key_id.
Next run:
curl -v -k -s -H "Content-Type: application/json" -H "Authorization: Bearer `gcloud auth application-default print-access-token`" "https://speech.googleapis.com/v1beta1/speech:syncrecognize" -d @sync-request.json
You should see:
{
"results": [
{
"alternatives": [
{
"transcript": "how old is the Brooklyn Bridge"
}
]
}
]
}