【问题标题】:Google speech API timeout time谷歌语音 API 超时时间
【发布时间】:2017-08-03 18:36:55
【问题描述】:

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

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

Retry total timeout exceeded before anyresponse was received

我在docs 中读到,异步调用的最大分钟数为每次调用 60 分钟,并且我已将文件上传到 Google Cloud Storage,因为超过 1 分钟的文件需要它。

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

【问题讨论】:

    标签: node.js timeout google-speech-api google-cloud-speech


    【解决方案1】:

    默认情况下,系统超时时间为 10 分钟。 This is a known issue for other Google Cloud services,但建议的修复对我不起作用,我认为当您运行代码并开始连接时需要设置其他内容。

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

    As written in the docs

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

    我将在这里参考node.js 示例,类似的概念将适用于其他人。 所以,当你得到你的回应时(不要使用承诺版本)给它一个回调,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

    【讨论】:

      【解决方案2】:

      我没有找到合适的方法将超时设置为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 分钟。

      如果有人知道更好的处理方法,请分享。 希望对您有所帮助。

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          猜你喜欢
          • 2018-04-10
          • 1970-01-01
          • 2016-11-04
          • 1970-01-01
          • 2014-12-16
          • 1970-01-01
          • 1970-01-01
          • 2023-04-09
          • 1970-01-01
          相关资源
          最近更新 更多