多个 StreamingRecognizeRequest

Multiple StreamingRecognizeRequest

我正在尝试使用多个请求设置 StreamingRecognize。可能吗?

重点是我想用 未知 时间从麦克风发送音频流,所以我认为我必须实施多个请求。 (考虑到请求会话有 max_time = 65 秒)。

谁能帮我解决这个问题?

非常感谢 ;)

Google示例代码:

static async Task<object> StreamingMicRecognizeAsync(int seconds)
{
if (NAudio.Wave.WaveIn.DeviceCount < 1)
{
    Console.WriteLine("No microphone!");
    return -1;
}
var speech = SpeechClient.Create();
var streamingCall = speech.StreamingRecognize();
// Write the initial request with the config.
await streamingCall.WriteAsync(
    new StreamingRecognizeRequest()
    {
        StreamingConfig = new StreamingRecognitionConfig()
        {
            Config = new RecognitionConfig()
            {
                Encoding =
                RecognitionConfig.Types.AudioEncoding.Linear16,
                SampleRateHertz = 16000,
                LanguageCode = "en",
            },
            InterimResults = true,
        }
    });
// Print responses as they arrive.
Task printResponses = Task.Run(async () =>
{
    while (await streamingCall.ResponseStream.MoveNext(
        default(CancellationToken)))
    {
        foreach (var result in streamingCall.ResponseStream
            .Current.Results)
        {
            foreach (var alternative in result.Alternatives)
            {
                Console.WriteLine(alternative.Transcript);
            }
        }
    }
});
// Read from the microphone and stream to API.
object writeLock = new object();
bool writeMore = true;
var waveIn = new NAudio.Wave.WaveInEvent();
waveIn.DeviceNumber = 0;
waveIn.WaveFormat = new NAudio.Wave.WaveFormat(16000, 1);
waveIn.DataAvailable +=
    (object sender, NAudio.Wave.WaveInEventArgs args) =>
    {
        lock (writeLock)
        {
            if (!writeMore) return;
            streamingCall.WriteAsync(
                new StreamingRecognizeRequest()
                {
                    AudioContent = Google.Protobuf.ByteString
                        .CopyFrom(args.Buffer, 0, args.BytesRecorded)
                }).Wait();
        }
    };
waveIn.StartRecording();
Console.WriteLine("Speak now.");
await Task.Delay(TimeSpan.FromSeconds(seconds));
// Stop recording and shut down.
waveIn.StopRecording();
lock (writeLock) writeMore = false;
await streamingCall.WriteCompleteAsync();
await printResponses;
return 0;

}

在 Cloud Speech-to-Text 中,每个流媒体请求的音频长度限制约为 1 分钟 [1]. You can either use asynchronous speech recognition [2] for audio files up to 180 minutes or renew the streaming request before it reaches to the time limit for streaming speech recognition [3]

这里是一个 Python 示例,说明如何更新流式传输请求和流式传输超过 1 分钟的音频 [4]