I'm trying to make a call to Google Speech API using the library method (I don't want to make a direct call to an endpoint) and I get this error:
The Application Default Credentials are not available.
They are available if running in Google Compute Engine.
Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS
must be defined pointing to a file defining the credentials.
I have already downloaded the JSON credentials file from my service account and defined the GOOGLE_APPLICATION_CREDENTIALS environment variable pointing to it.
I have also created this GCLOUD_PROJECT variable which is set to the "project_id" field in my JSON file.
I am not providing any extra authentication when using the library method - but this has worked in another local environment which probably had some other configuration that I am missing.
var speech = SpeechClient.Create();
var response = speech.Recognize(new RecognitionConfig()
{
Encoding = RecognitionConfig.Types.AudioEncoding.Linear16,
LanguageCode = languageCode,
}, RecognitionAudio.FromFile(file));
The authentication file is of type service account, if that helps.
"type": "service_account",
Setting the environment variable worked for me. Use the code:
System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", <<path>>);
You need to use path of json file that you get from Google Api page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With