0

I am trying to use Google Speech API v1 in .net and facing a challange in making a call.

Below is my code.

Dim userSpeech = Google.Cloud.Speech.V1.SpeechClient.Create
Dim response = userSpeech.Recognize(New RecognitionConfig, RecognitionAudio.FromFile(filePath))
For Each result In response.Results
    For Each alternative In result.Alternatives
         Console.WriteLine(alternative.Transcript)
    Next
Next

I never reach line of first FOR. I also don't get any error. The API is enabled. Google Cloud Credentials are set as environment variables. So, no problem there.

Then I tried in C# as below. But I get exact same result i.e. I don't get to foreach line.

var speech = SpeechClient.Create();
var response = speech.Recognize(new RecognitionConfig()
               {
                    Encoding = RecognitionConfig.Types.AudioEncoding.Linear16,
                    SampleRateHertz = 16000,
                    LanguageCode = "en",
                }, RecognitionAudio.FromFile("audio.raw"));


 textBox1.Text = "";

 foreach (var result in response.Results)
 {
        foreach (var alternative in result.Alternatives)
        {
               textBox1.Text = textBox1.Text + " " + alternative.Transcript;
         }
 }

Other API calls in the same application works e.g. language detection.

Any help will be highlight appreciated.

Thanks in advance.

Sukhi
  • 13,261
  • 7
  • 36
  • 53

1 Answers1

2

Make sure you have Installed the Google Cloud SDK and authenticated by running the following command:

gcloud auth application-default login

Alexander Higgins
  • 6,765
  • 1
  • 23
  • 41
  • Thanks Alexander. No, I haven't installed Google Cloud SDK yet. Thought NL APIs are working well so speech APIs would work too. Nevertheless, I'll install the SDK. Thanks again, Alexander. – Sukhi Jul 17 '17 at 06:26
  • Glad to help. You can mark this answer correct so others with the same issue know how you fixed it. – Alexander Higgins Jul 17 '17 at 06:27
  • Hi Alexander. Yes, I would do that. I am trying to install Google SDK since yesterday but there's a problem. I tried with both interactive and non-interactive installers. Give me a day or two and I'll mark your answer as correct. – Sukhi Jul 17 '17 at 16:41