如何在 Google Speech-to-Text API 中处理多个 streamingRecognize 请求?

How to proceed multiple streamingRecognize request in Google Speech-to-Text API?

我已经使用 Google Speech-to-Text API.

构建了一个基于 Web 的 Speech-to-Text 应用程序

申请流程:

  1. 从浏览器获取音频流
  2. 将音频数据流式传输到语音识别服务,并在我们的用户谈话时获得实时结果

我在我的应用程序中引用了 sample codestreamingRecognize 请求与信号客户端调用完美配合,我的服务器可以从 Google 语音接收临时转录结果API。 但是,当有多个客户端同时调用 streamingRecognize 时,Google 语音 API 会卡住。那么,我可以知道如何同时处理多个 streamingRecognize 请求吗?我是否需要创建另一个 client 来处理第二个 streamingRecognize 请求?谢谢。

后端服务器规格:

尝试做同样的事情,遇到和你一样的麻烦,或者他们停止工作,或者只有一个客户不时工作而其他客户给出奇怪的结果,有时两者都有,看起来你的主账户只有一个缓冲区,您是否尝试过为每个用户生成 api/tokens?值得吗,还是会有相同的缓冲区

您应该能够创建多个 streaming threads by using the same StreamingRecognize() client, the ones that can be used to send the requests in parallel. You can take a look on this and this Github 讨论此主题的帖子。

我建议您尝试此替代方法并验证是否可以通过创建 2 个不同的 objectsclients 来执行这些流式调用,例如如:

const client = new speech.SpeechClient();
const recognizeStream = client.streamingRecognize(request)
...
const recognizeStream2 = client.streamingRecognize(request)
...

另一方面,如果要批量进行语音识别,还是比较推荐使用synchronous or asynchronous的方法。