LoginSignup
4
3

More than 5 years have passed since last update.

google cloud speech API

Last updated at Posted at 2017-03-05

クイックスタート

サンプルの音声を利用

sync-request.json
{
  "config": {
      "encoding":"FLAC",
      "sampleRate": 16000,
      "languageCode": "en-US"
  },
  "audio": {
      "uri":"gs://cloud-samples-tests/speech/brooklyn.flac"
  }
}

サービスアカウントの認証

cloud auth activate-service-account --key-file=<path/to/service-account-key.json>

認証トークンの取得

gcloud auth print-access-token

リクエスト発行

curl -s -k -H "Content-Type: application/json" \
    -H "Authorization: Bearer <access_token>" \
    https://speech.googleapis.com/v1beta1/speech:syncrecognize \
    -d @sync-request.json

結果

{
  "results": [
    {
      "alternatives": [
        {
          "transcript": "how old is the Brooklyn Bridge",
          "confidence": 0.98267895
        }
      ]
    }
  ]
}

日本語でやってみた

使用データ (E-13)
mp3→flac変換
(その前にsoxをaptgetでインストールし、mp3のライブラリ→libsox-fmt-mp3もapt-getでインストール)

sox narration.mp3 narration.flac channels 1 rate 16k

flacをアップロード

gsutil cp narration.flac gs://<bucket>/narration.flac

リスエスト編集

sync-request.json
{
  "config": {
      "encoding":"flac",
      "sampleRate": 16000,
      "languageCode": "ja-JP"
  },
  "audio": {
      "uri":"gs://<bucket>/narration.flac"
  }
}

リクエスト実行

curl -s -k -H "Content-Type: application/json" \
-H "Authorization: Bearer <access_token>" https://speech.googleapis.com/v1beta1/speech:syncrecognize \
-d @sync-request.json

結果

{
  "results": [
    {
      "alternatives": [
        {
          "transcript": "出展企業200社を揃え3万人が集う日本最大規模のデジタルクリエーター見本市デジタルクリエイト2007が8月29日に幕張メッセにて開幕します",
          "confidence": 0.75
        }
      ]
    }
  ]
}
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3