【问题标题】:Google Speech API Call谷歌语音 API 调用
【发布时间】:2017-07-15 17:10:57
【问题描述】:

我正在尝试在 .net 中使用 Google Speech API v1,但在拨打电话时遇到了挑战。

下面是我的代码。

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 凭据设置为环境变量。所以,没问题。

然后我在 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 调用有效,例如语言检测。

任何帮助将不胜感激。

提前致谢。

【问题讨论】:

  • 达不到是什么意思?是抛出异常还是Recognize 挂起而不返回?
  • 您还安装了 Google Cloud SDK 并通过运行以下命令进行身份验证:gcloud auth application-default login

标签: c# vb.net google-speech-api


【解决方案1】:

确保您已安装 Google Cloud SDK 并通过运行以下命令进行身份验证:

gcloud auth application-default login

【讨论】:

  • 谢谢亚历山大。不,我还没有安装 Google Cloud SDK。认为 NL API 运行良好,因此语音 API 也可以运行。不过,我将安装 SDK。再次感谢亚历山大。
  • 很高兴为您提供帮助。您可以将此答案标记为正确,以便其他有相同问题的人知道您是如何解决的。
  • 嗨,亚历山大。是的,我会那样做。我从昨天开始尝试安装 Google SDK,但出现了问题。我尝试了交互式和非交互式安装程序。给我一两天,我会把你的答案标记为正确的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-12-16
  • 1970-01-01
  • 1970-01-01
  • 2023-04-09
  • 1970-01-01
  • 2017-03-08
  • 1970-01-01
相关资源
最近更新 更多