我正在尝试在.net中使用谷歌语音API v1,并在拨打电话时面临挑战。谷歌语音API调用
以下是我的代码。
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
我从来没有达到第一个FOR的行。我也没有得到任何错误。该API已启用。 Google Cloud Credentials被设置为环境变量。所以,那里没有问题。
然后我尝试在C#如下。但我得到完全相同的结果,即我没有达到foreach行。
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;
}
}
在同一应用程序中的其他API调用工作,例如,语言检测。
任何帮助将被高度赞赏。
在此先感谢。
你是什么意思你没有达到呢?有没有抛出异常,或者“识别”挂起而不回来? –
您还需要安装Google Cloud SDK并通过运行以下命令进行身份验证:'gcloud auth application-default login' –