錯誤訊息

本頁面說明 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 提供憑證,請參閱「設定應用程式預設憑證」。

檔案 ... (由 GOOGLE_APPLICATION_CREDENTIALS 環境變數指向) 不存在!

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

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.

您的音訊檔案包含多個頻道。如要轉錄這個音訊檔案,您必須宣告音訊具有多個聲道。

「LINEAR_PCM 必須使用 16 位元樣本」

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

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 的大小上限。您可以將音訊檔案移至 Cloud Storage bucket,避免 10 MB 的限制。詳情請參閱配額與限制頁面。

「Quota exceeded」(超過配額)

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

RESOURCE_EXHAUSTED: Quota exceeded.

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

您可以透過 Google Cloud 控制台申請提高配額。