【问题标题】:Google Speech API - Server Unavailable Error for long audio filesGoogle Speech API - 长音频文件的服务器不可用错误
【发布时间】:2018-11-05 23:36:51
【问题描述】:

我正在使用 Google 的 nodejs-speech 包来使用 Google 语音 API 中的 longRunningRecognize 端点/函数。

我同时使用了v1v1p1beta,但在文件较长时遇到了错误。 (我试过 48 分钟,15 分钟会导致同样的问题,但 3 分钟不会)。我已经尝试过 promise 模式并将请求分为两部分 - 一个启动 longRunningRecognize 过程,另一个在等待后检查结果。错误显示在两者的代码示例下方。

请求的承诺版本示例:

import speech from '@google-cloud/speech';

const client = new speech.v1p1beta1.SpeechClient();

const audio = {
  uri: 'gs://my-bucket/file.m4a'
};

const config = {
  encoding: 'AMR_WB',
  sampleRateHertz: 16000,
  languageCode: 'en-US',
  enableWordTimeOffsets: true,
  enableSpeakerDiarization: true
};

const request = {
  audio,
  config
};

client.longRunningRecognize(request)
  .then(data => {
    const operation = data[0];
    return operation.promise();
  })
  .then(data => {
    const response = data[0];
    const results = response.results;
    const transcription = results
      .filter(result => result.alternatives)
      .map(result => result.alternatives[0].transcript)
      .join('\n');
    console.log(transcription);
  })
  .catch(error => {
    console.error(error);
  });

(我已经关闭了显示结果的选项卡,但我认为这返回了一个错误对象,上面写着{ error: { code: 13 } },它与下面的更具描述性的错误相匹配)。

另外,我尝试了一个版本,而不是链接承诺来获得最终的转录结果,我从操作中收集name,并发出单独的请求以获取结果。

这是请求代码:

... // Skipping setup
client.longRunningRecognize(request)
  .then(data => {
    const operation = data[0];
    console.log(operation.latestResponse.name);
  })
  .catch(error => {
    console.error(error);
  });

当我在有时间处理之前点击相关端点 (https://speech.googleapis.com/v1p1beta1/operations/81703347042341321989?key=ABCD12345) 时,我得到了这个:

{
    "name": "81703347042341321989",
    "metadata": {
        "@type": "type.googleapis.com/google.cloud.speech.v1p1beta1.LongRunningRecognizeMetadata",
        "startTime": "2018-08-16T19:33:26.166942Z",
        "lastUpdateTime": "2018-08-16T19:41:31.456861Z"
    }
}

不过,一旦它完全处理完毕,我就遇到了这个问题:

{
    "name": "81703347042341321989",
    "metadata": {
        "@type": "type.googleapis.com/google.cloud.speech.v1p1beta1.LongRunningRecognizeMetadata",
        "progressPercent": 100,
        "startTime": "2018-08-16T17:20:28.772208Z",
        "lastUpdateTime": "2018-08-16T17:44:40.868144Z"
    },
    "done": true,
    "error": {
        "code": 13,
        "message": "Server unavailable, please try again later."
    }
}

我尝试过使用较短的音频文件(3 分钟,相同的格式和编码),并且上述过程都有效。

知道发生了什么吗?

【问题讨论】:

  • 如果音频开头有长时间的静音,则可能会发生这种错误。您的音频文件会是这种情况吗?在这些情况下,有时将文件的编码更改为 FLAC 会很有帮助。
  • 其中大部分没有长时间的沉默,但我可以尝试 Flac 并报告。
  • Flac 成功了!谢谢!而且很奇怪。感觉这里的错误可能会更清楚。

标签: javascript google-cloud-platform google-speech-api


【解决方案1】:

一种可能的解决方法是将音频格式更改为 FLAC,这是 Cloud Speech-to-text API 的推荐编码类型,因为它具有无损压缩。

作为参考,这可以通过以下命令使用sox 完成:

sox file.m4a --rate 16k --bits 16 --channels 1 file.flac

另外,这个错误也可能发生在开头有很长一段时间的静默时。在这种情况下,可以通过在trim 之后指定音频应在文件开头和结尾跳过的秒数来修剪音频文件:

sox input.m4a --rate 16k --bits 16 --channels 1 output.flac trim 20 5

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多