配置 Google Cloud Speech API 的語音辨識

對於 Google Cloud Speech API,您可以變更 RecognitionConfig API 的預設配置。例如,您可以切換不雅言辭的過濾、變更語言,或是新增語音環境定義。如果您想變更服務的預設行為,只需指定任何 Cloud Speech API 配置即可。

如果要變更預設配置,您可以:

建立個別的 JSON 檔案,可讓您定義更多的欄位(尤其是語音環境定義)。若有欄位同時定義在這兩處,則會優先採用 JSON 檔案中指定的值。

在部署配置中配置 Google Cloud Speech API

如果要將 Google Cloud Speech API 配置成 Speech to Text Adapter 部署的一部分,請定義 GOOGLE_SPEECH 環境變數。如需完整的配置環境變數清單,請參閱 Speech to Text Adapter 環境變數

在 JSON 檔案中配置 Google Cloud Speech API

  1. 建立 recognitionConfig.json 檔,並以 JSON 格式來定義 RecognitionConfig API 中的欄位。sample.voice.gateway GitHub 儲存庫中的 stt-adapter 資料夾含有一個可供您著手進行的範例 recognitionConfig.json 檔。

    重要事項:RecognitionConfig API 的欄位必須以峰式大小寫格式指定在 recognitionConfig.json 檔中。以 language_code 欄位為例,請改成指定 languageCode

    {
     "languageCode": "es-ES"
    }
    

    附註:Cloud Speech API 中之 RecognitionConfig 的下列欄位無法修改,因為它們具有 Speech to Text Adapter 使用的固定值。

    • encoding
    • sample_rate_hertz
  2. stt.adapter 儲存器的配置中,將 recognitionConfig.json 檔裝載在磁區上,並在 GOOGLE_SPEECH_RECOGNITION_CONFIG 環境變數上參照檔案位置。

    例如,在 Docker 上:

    stt.adapter:
     ...
     environment:
       - GOOGLE_APPLICATION_CREDENTIALS=/stt-adapter/credentials/google-service-account.json
       - GOOGLE_SPEECH_RECOGNITION_CONFIG=/stt-adapter/recognitionConfig.json
     volumes:
       - "/path/to/credentials/google-service-account.json:/stt-adapter/credentials/google-service-account.json"
       - "./recognitionConfig.json:/stt-adapter/recognitionConfig.json"
    

下一步

變更配置之後,請重新部署具有 Speech to Text Adapter 的 Voice Gateway,以便讓您所做的變更生效。