C# 在PCL内通过Google云语音API认证
我正试图在我的Xamarin.Forms PCL项目(可移植类库)中验证Google云语音Api。我正在用安卓手机进行测试。我的解决方案的代码如下所示:C# 在PCL内通过Google云语音API认证,c#,android,xamarin,xamarin.forms,google-cloud-speech,C#,Android,Xamarin,Xamarin.forms,Google Cloud Speech,我正试图在我的Xamarin.Forms PCL项目(可移植类库)中验证Google云语音Api。我正在用安卓手机进行测试。我的解决方案的代码如下所示: Assembly assembly = typeof(Program).GetTypeInfo().Assembly; Stream stream = assembly.GetManifestResourceStream("ConsoleApp1.speech_auth.json"); stri
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"));
在一个普通的.NET控制台应用程序项目中,它的工作非常出色。但是,如果我在我的PCL项目中尝试完全相同的代码,我会在以下行中得到一个错误:
var channel = new Grpc.Core.Channel(SpeechClient.DefaultEndpoint.Host,
credential.ToChannelCredentials());
上面说:
未处理的异常:
System.NotImplementedException:方法或操作未实现
我已经在我的PCL和Android项目上安装了所有Nuget GRPC和Google Speech API包
因此,我的问题是:
是否有更好/更简单的方法使用Xamarin.Forms对谷歌云语音API进行身份验证?如果没有,我的代码有什么问题?
编辑:似乎Xamarin是这样做的。
我已经设法使用一个简单的httpClient调用语音API发送请求。Grpc似乎缺少Xamarin支持。请求支持时记录了一个问题。您能提供您用于谷歌云语音API的NuGet软件包的确切名称吗?@Timklingeers谢谢您的回复!实际上,我使用Google.Cloud.Speech.V1(1.0.0 beta-08)进行语音识别,使用Google.api(1.25.0)和Google.api.Auth(1.25.0)进行谷歌云的身份验证。Grpc似乎缺少Xamarin支持。请求支持时记录了一个问题。您能提供您用于谷歌云语音API的NuGet软件包的确切名称吗?@Timklingeers谢谢您的回复!实际上,我使用Google.Cloud.Speech.V1(1.0.0 beta-08)进行语音识别,使用Google.api(1.25.0)和Google.api.Auth(1.25.0)进行谷歌云的身份验证。