首页 文章

Google语音API超时时间

提问于
浏览
1

我正在尝试使用Speech API客户端API将音频文件转换为文本 .

到目前为止,我已经成功转换了一个短的音频剪辑,但现在有一个更长的文件(10分钟),我得到这个错误:

Retry total timeout exceeded before anyresponse was received

我已经在docs中读到,对于异步呼叫,每个呼叫的最大分钟数为60,并且我已将文件上传到Google Cloud 端存储,因为文件需要超过1分钟 .

所以我真的不明白为什么我会收到这个错误,有什么帮助吗?

3 回答

  • 0

    默认情况下,系统超时为10分钟 . This is a known issue for other Google Cloud services,但是修复建议那里没有用,我认为当你运行代码并开始连接时,这是另一个设置 .

    无论如何,有一个解决方法!您获得长时间运行的操作名称,然后停止您的程序 . 该操作将在谷歌服务器上继续,稍后您将获取结果!

    As written in the docs

    异步语音识别启动长时间运行的音频处理操作 .

    我将在这里参考 node.js 样本,类似的概念将适用于其他人 . 所以,当你收到你的回复(不要使用promise版本)时,传递一个回调,like explained here,而不是

    operation
        .on('error', function(err) {})
        .on('complete', function(transcript) {
          // transcript = "how old is the Brooklyn Bridge"
        });
    

    做一些像

    console.log(operation)
    

    记下操作名称,稍后再使用the operation method

    You can test these on the google oauth playground

  • 0

    对于其他任何有此问题的人,Google现在已通过删除超时值修复了此错误 . 请参阅https://github.com/googleapis/gax-nodejs/pull/140/files我的语音api请求现在可以在更新到最新的google-gax npm包后成功运行 .

  • 1

    我没有找到一个正确的方法来设置超时超过10分钟,所以我直接修改了 node_modules/google-gax/lib/longrunning.js . 有一个名为 backoffSettings 的变量保存超时值,它是对 node_modules/google-gax/lib/gax.js 中函数 createBackoffSettings 的调用 . 在我修改该变量之前,它是这样的:

    backoffSettings =
            createBackoffSettings(100, 1.3, 60000, null, null, null, 600000);
    

    我把它更改为处理1小时超时:

    backoffSettings =
            createBackoffSettings(100, 1.3, 60000, null, null, null, 3600000);
    

    createBackoffSettings 函数调用中的最后一个参数是 totalTimeoutMillis ,如您所见默认为10分钟 .

    如果有人知道更好的方法来处理它,请分享 . 希望能帮助到你 .

相关问题