错误消息

了解如何解决 Speech-to-Text 引发的一些错误。本主题讨论解决方法需要多个步骤且无法在错误消息中简单说明的错误。

“The Application Default Credentials are not available”

如果收到此消息:

The Application Default Credentials are not available. They are
available if running in Google Compute Engine. Otherwise, the
environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined
pointing to a file defining the credentials.
See https://developers.google.com/accounts/docs/application-default-credentials
for more information.

Speech-to-Text 使用应用默认凭据 (ADC) 进行身份验证。

ADC 凭据必须在您调用 Speech-to-Text API 的上下文中可用。例如,如果您在终端中设置 ADC,但在 IDE 的调试程序中运行代码,则代码的执行上下文可能无法访问凭据。在这种情况下,您对 Speech-to-Text 发出的请求可能会失败。

如需了解如何向 ADC 提供凭据,请参阅设置应用默认凭据

“File ... (pointed by GOOGLE_APPLICATION_CREDENTIALS environment variable) does not exist!”

如果收到此消息:

ERROR: (gcloud.auth.application-default.print-access-token) File /path/to/key.json
(pointed by GOOGLE_APPLICATION_CREDENTIALS environment variable) does not exist!
{
  "error": {
    "code": 403,
    "message": "The request is missing a valid API key.",
    "status": "PERMISSION_DENIED"
  }
}

确认 GOOGLE_APPLICATION_CREDENTIALS 环境变量中存储的位置中包含有效的服务账号密钥 JSON 文件,并且该变量指向正确的位置。

要诊断此错误,请从您尝试调用 Speech-to-Text API 的文件夹中打开服务账号密钥文件。

cat $GOOGLE_APPLICATION_CREDENTIALS

Forbidden: 403 POST API has not been used or is disabled

如果收到此消息:

Forbidden: 403 POST Speech-to-Text API has not been used in
project # before or it is disabled.
Enable it by visitng [url] then retry.
If you enabled this API recently, wait a few minutes for the action to
propagate to our systems and retry.

  1. 访问错误消息中指定的链接,并启用 Speech-to-Text API。 等待几分钟,然后重试。
  2. 验证您是否在 GOOGLE_APPLICATION_CREDENTIALS 环境变量中存储了有效的服务账号密钥 JSON 文件。要诊断此错误,请从您尝试调用 Speech-to-Text API 的文件夹中打开服务账号密钥文件。
    cat $GOOGLE_APPLICATION_CREDENTIALS
    

“Must use single channel (mono) audio”

如果收到此消息:

Must use single channel (mono) audio, but WAV header indicates 2
channels.

您的音频文件包含多个通道。要转录此音频文件,您必须声明您的音频有多个通道

“Must use 16 bit samples for LINEAR_PCM”

如果收到此消息:

INVALID_ARGUMENT: Must use 16 bit samples for LINEAR_PCM, but the WAV
header indicates 8 bits per sample

您可能需要更改在 RecognitionConfig 中指定的编码。如需了解 Speech-to-Text 中支持的编码,请参阅编码指南。

“Sync input too long”

如果收到此消息:

Sync input too long. For audio longer than 1 min use
LongRunningRecognize with a 'uri' parameter.

Speech-to-Text 的同步识别方法只支持转录最长一分钟的音频数据。对于较长的音频数据,请改用异步识别

“Invalid recognition 'config': bad encoding”

如果收到此消息:

Invalid recognition 'config': bad encoding.

您的音频数据可能未正确编码,或编码时所使用的编解码器与您在 RecognitionConfig 中声明的编解码器不同。请检查音频输入并确保已正确设置 encoding 字段。

“Request payload size exceeds the limit”

如果您收到以下任一条消息:

Request payload size exceeds the limit.
Inline audio exceeds duration limit. Please use a GCS URI.

使用本地文件发送至 API 的单个请求的大小已超过 10 MB 的限制。您可以将音频文件移动到 Google Cloud Storage (GCS) 存储分区,以避免超过 10 MB 的限制。如需了解详情,请参阅配额和限制页面。

“Quota exceeded”

如果收到此消息:

RESOURCE_EXHAUSTED: Quota exceeded.

您已达到每分钟或每日配额的上限。请查看使用 Speech-to-Text 的配额和限制

您可以通过 Google Cloud Console 申请增加配额。