对 google 流式语音识别进行一些更改,但它不起作用

Make some changes of google streaming speech recognition and it does not work

我正在处理 google 流式语音 recognition.Now 我正在尝试从 WriteAsync 中取出参数,但我不明白为什么我无法接收到任何参数文本。 这是之前的代码:

 await streamingCall.WriteAsync(
      new StreamingRecognizeRequest()
      {
          StreamingConfig = new StreamingRecognitionConfig()
          {
              Config = new RecognitionConfig()
              {
                Encoding = RecognitionConfig.Types.AudioEncoding.Linear16,
                SampleRateHertz = 32000,
                LanguageCode = "en",
               },
                InterimResults = true,
            }
       });

这是我做了一些修改的代码:

RecognitionConfig config = new RecognitionConfig();
config.Encoding = RecognitionConfig.Types.AudioEncoding.Linear16;
config.SampleRateHertz = 32000;
config.LanguageCode = "en";
await streamingCall.WriteAsync(
  new StreamingRecognizeRequest()
   {
      StreamingConfig = new StreamingRecognitionConfig()
       {
         InterimResults = true,
        }
    });

您没有使用 RecognitionConfig:

RecognitionConfig config = new RecognitionConfig();
config.Encoding = RecognitionConfig.Types.AudioEncoding.Linear16;
config.SampleRateHertz = 32000;
config.LanguageCode = "en";
await streamingCall.WriteAsync(
    new StreamingRecognizeRequest()
    {
        StreamingConfig = new StreamingRecognitionConfig()
        {
            Config = config, // You are missing this line
            InterimResults = true,
        }
    });