I'm currently trying to access the cloud API and I am receiving 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 gone onto my google cloud platform account, enabled billing, created a service account, downloaded a JSON key and set GOOGLE_APPLICATION_CREDENTIALS in my environment variables and have checked that it's pointing to the correct JSON key. It is pointing to my API key 'C:\Users\jade.wilson\source\repos\CloudApi\CloudApi\Services\Keys\CloudAPIKey.json'
This is the code:
var credential = GoogleCredential.GetApplicationDefault();
var channel = new Grpc.Core.Channel(SpeechClient.DefaultEndpoint.ToString(), credential.ToChannelCredentials());
var client = SpeechClient.Create(channel);
response = await client.RecognizeAsync(new RecognitionConfig()
{
Encoding = RecognitionConfig.Types.AudioEncoding.Linear16,
SampleRateHertz = 16000,
LanguageCode = "en",
}, RecognitionAudio.FromStream(audio));
It is not getting past the first line. Is there something else I am missing?
GOOGLE_APPLICATION_CREDENTIALSexactly? If that environment variable is set, I'd expect you to get a different error if the file is wrong etc. (I could be wrong on that front, mind you.) If you logEnvironment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS")on start-up, do you see the value you expect? (My guess is that you've set the environment variable for one user, but not the user running the code.) Also note that just usingvar client = SpeechClient.Create();is the simple way to use the default endpoint and default credentials. - Jon Skeet