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.