1

I'm trying to authenticate to the Google Cloud Speech Api within my Xamarin.Forms PCL-Project (Portable Class Library). I'm testing with an Android-Phone. The code of my solution looks like:

        Assembly assembly = typeof(Program).GetTypeInfo().Assembly;
        Stream stream = assembly.GetManifestResourceStream("ConsoleApp1.speech_auth.json");

        string resultString = null;

        using (StreamReader reader = new StreamReader(stream))
        {
            resultString = reader.ReadToEnd();
        }

        GoogleCredential credential = GoogleCredential.FromJson(resultString);

        if (credential.IsCreateScopedRequired)
        {
            credential = credential.CreateScoped(new[] { "https://www.googleapis.com/auth/cloud-platform" });
        }

        var channel = new Grpc.Core.Channel(SpeechClient.DefaultEndpoint.Host,
            credential.ToChannelCredentials());

        var speech = SpeechClient.Create(channel);
        var response = speech.Recognize(new RecognitionConfig()
                                            {
                                                Encoding = RecognitionConfig.Types.AudioEncoding.Flac,
                                                SampleRateHertz = 16000,
                                                LanguageCode = "de-CH",
                                            }, RecognitionAudio.FromFile("test.flac"));

In a usual .NET ConsoleApplication-Project, its working like a charm. However, if i try exactly the same code within my PCL-Project i get an error on the following line:

 var channel = new Grpc.Core.Channel(SpeechClient.DefaultEndpoint.Host,
            credential.ToChannelCredentials());

which says:

Unhandled Exception: System.NotImplementedException: The method or operation is not implemented

I have installed all Nuget GRPC and Google Speech API-Packages on my PCL and on my Android-Project.

So my questions are:

Is there a better / easier way to authenticate to the Google Cloud Speech API, using Xamarin.Forms? If not, whats the problem with my code?

Edit: It seems that Xamarin does not support gRPC. I've managed to call the speech API sending a request using a simple httpClient.

Tobias von Falkenhayn
  • 1,355
  • 5
  • 26
  • 59
  • Grpc seems to lack Xamarin support. There is an issue logged at [their GitHub project](https://github.com/grpc/grpc/issues/1620) asking for support. Could you provide the exact name of the NuGet package you are using for the Google Cloud Speech API? – Tim Klingeleers May 02 '17 at 19:35
  • @TimKlingeleers thanks for your reply! I'm actually using the Google.Cloud.Speech.V1 (1.0.0 beta-08) for speech recognition as well as the Google.Apis (1.25.0) and the Google.Apis.Auth (1.25.0) for authentication with the google cloud. – Tobias von Falkenhayn May 03 '17 at 08:58

0 Answers0