Google Speech API 使用記錄

aha (Cheng-Yu Lin)
2 min readNov 1, 2017

--

google說明文件

解構

  1. 使用這個功能主要是先有一個google cloud platform的帳號
  2. 啟用一個專案,並且啟用 google speech api,最後拿到使用金鑰
  3. HOST: speech.googleapis.com
  4. method: POST
  5. endpoint: /v1/speech:longrunningrecognize
  6. queryString: key

範例

[POST] https://speech.googleapis.com/v1/speech:longrunningrecognize?key=<key>body{  
"config": {
"encoding":"FLAC",
"sampleRateHertz": 8000,
"language_code": "cmn-Hant-TW",
"enableWordTimeOffsets": false },
"audio": {
"uri":"gs://<bucket_name>/<file_name>"
}
}

回傳範例

{
"name": "7612202767953098924"
}

因為這是使用speech:longrunningrecognize,所以在等待一段時間之後,可以透過這次回傳的資料operation name的資訊。在拿到完整的翻譯資訊

[GET] https://speech.googleapis.com/v1/operations/OPERATION_NAME?key=API_KEY

最後說明

  1. 聲音檔要轉成flac格式,並且為單聲道,同時也要確認音頻[待補,找到更優雅的做法]

--

--

aha (Cheng-Yu Lin)
aha (Cheng-Yu Lin)

Written by aha (Cheng-Yu Lin)

Passionate about reading, gaming, and travel. Using AI to connect the physical & virtual worlds, I enjoy sharing ideas with others. Let's connect!

No responses yet