呼叫Google Cloud Speech API不会返回任何内容,10分钟后会失败

9 c# google-app-engine speech-recognition google-cloud-platform google-speech-api

我正在尝试使用Google.Cloud.Speech.V1(Google Cloud Speech API的客户端库),我正在使用这个稍微修改过的Google示例代码版本:

public async Task<string> TranscribeSpeech(string filenameAndPath, int WAVSampleRate = 8000)
    {
        Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", Utils.GetHomeFolder() + @"\Google Speech API Key.json"); //for authentication

        var language = WebConfigurationManager.AppSettings["GoogleSpeechFromLocale"];

        var speech = SpeechClient.Create();
        var response = await speech.RecognizeAsync(new RecognitionConfig()
        {
            Encoding = RecognitionConfig.Types.AudioEncoding.Linear16,
            SampleRateHertz = WAVSampleRate,
            LanguageCode = language,
        }, RecognitionAudio.FromFile(filenameAndPath));

        return response.Results.First().Alternatives.First().Transcript;
    }
Run Code Online (Sandbox Code Playgroud)

.Recognize().RecognizeAsync()方法不返回任何东西,10分钟后说:抛出异常Status(StatusCode=DeadlineExceeded,Detail="Deadline Exceeded")!.

换句话说,当我在Visual Studio中逐行调试时,代码在await之后永远不会继续,speech.RecognizeAsync()并且只是保持挂起状态,直到它在10分钟后抛出异常.

我的代码或API设置是否存在问题?

我的输入文件通常只有2-3秒长,并具有以下格式(输出ffmpeg):

Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 8000 Hz, mono, s16, 128 kb/s

我的应用程序代码托管在Azure上.Google云端平台控制台显示没有API调用 - 这可能意味着我的请求无法以某种方式到达Google服务器.

同一个应用程序也会调用Bing Speech API并且它们是成功的.

如果我使用相同的WAV文件运行来自https://developers.google.com/apis-explorer/?hl=en_US#p/speech/v1beta1/speech.speech.syncrecognize的调用,则会成功.

Kin*_*oad 4

我认为您遵循了安装指南: https: //cloud.google.com/speech/docs/reference/libraries如果您这样做了,一切都应该正常工作。

但是,您可以使用它的上限是多少。

1.含量限制:

1-1 Synchronous Requests1分钟左右。

1-2Asynchronous Requests约80分钟。

1-3 Streaming Requests,也在1分钟左右。

2 语音上下文限制:

2-1 的Phrases per request值上升到 500。

2-2Total characters per request最多 10k 个字符。

2-3Characters per phrase上升到 100。

超过 1 分钟的音频必须使用该uri字段来引用 Google Cloud Storage 中的音频文件。

对于 StreamingRecognize 请求,音频必须以接近实时的速率发送。

尝试处理超出这些内容限制的内容将会产生错误。

如果您想了解更多限制,Google Speech API我建议您查看以下内容: https: //cloud.google.com/speech/limits,因为我在另一个 google API 中也遇到了超出限制的相同错误。