錯誤訊息

本頁面討論的 Cloud 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.

Cloud STT 使用應用程式預設憑證 (ADC) 進行驗證。

您呼叫 Cloud Speech-to-Text API 時,ADC 的憑證必須在該環境中可用。舉例來說,如果您在終端機中設定 ADC,但在 IDE 的偵錯工具中執行程式碼,程式碼的執行環境可能無法存取憑證。在這種情況下,您對 Cloud STT 的要求可能會失敗。

如要瞭解如何向 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 檔案,且該變數指向正確的地方。

如要診斷此錯誤,請嘗試從您想呼叫 Cloud Speech-to-Text API 的資料夾開啟服務帳戶金鑰檔案。

cat $GOOGLE_APPLICATION_CREDENTIALS

禁止:403 POST API 未使用或已停用

如果收到以下訊息:

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

  1. 前往錯誤訊息中指定的連結,並啟用 Cloud STT API。請稍候幾分鐘,然後再試一次。
  2. 確認您存在 GOOGLE_APPLICATION_CREDENTIALS 環境變數中的位置具有有效的服務帳戶金鑰 JSON 檔案。如要診斷此錯誤,請嘗試從您想呼叫 Cloud 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」(必須使用 16 位元樣本進行 LINEAR_PCM)

如果您收到以下這則訊息:

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

您可能需要變更在 RecognitionConfig 中指定的編碼。如要瞭解 Cloud STT 支援的編碼方式,請參閱編碼指南。

「Sync input too long」(同步處理輸入作業的時間過長)

如果您收到以下這則訊息:

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

Cloud STT 的同步辨識方法僅支援最長 1 分鐘的轉錄音訊資料。如果是更長的音訊資料,請改用非同步辨識

「Invalid recognition 'config': bad encoding」(無效的辨識 'config':編碼有誤)

如果您收到以下這則訊息:

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 的大小上限。如要避免 10 MB 的大小限制,請將音訊檔案移至 Cloud Storage 值區。詳情請參閱「配額與限制」頁面。

「Quota exceeded」(超過配額)

如果您收到以下這則訊息:

RESOURCE_EXHAUSTED: Quota exceeded.

您已達到每分鐘或每日配額的上限。請查看使用 Cloud STT 的配額與限制

您可以透過Google Cloud 控制台要求增加配額。