回答

1

這是我如何形成JSON有效載荷包括SpeechContext提供關鍵短語,在這種情況下「烤土豆」和「kerfuffle的」:

{ 
    "config": { 
     "encoding": "LINEAR16", 
     "sampleRateHertz": 16000, 
     "languageCode": locale, 
     "speechContexts": [ 
      { 
       "phrases": [ 
        "baked potato", 
        "kerfuffle", 
       ], 
      } 
     ], 
    }, 
    "audio": { 
     "content": encoded_audio, 
    } 
} 

其中locale是一個變量保持語言代碼和encoded_audio是保存音頻的字節字符串。

提供此語音上下文很好地解決了Google翻譯解決我的應用程序特定關鍵短語時遇到的問題。