IBM Watson Speech to Text API セットアップ + 日本語対応
音声を文字におこすWatsonのAPIを使うためにIBMのサイトとパソコンからの通信環境をセットアップする方法
API:
Speech to Text | IBM Watson Developer Cloud
公式チュートリアル:Speech to Text | Getting started | IBM Watson Developer Cloud
0:利用のための各種登録
Bluemixへ登録する。
https://console.ng.bluemix.net/registration/
ログインする。
クレジットカードを登録する。
Speech to Text APIを利用するためにはプロフィールページからクレジットカードを登録しなければいけない。
結果としてAccount TypeがPremium(以下のような画面)になれば、Speech to Text APIを利用できる。
1: flac ファイルをダウンロード
Speech to Text | Getting started | IBM Watson Developer Cloud より、以下でデモデータとして扱うファイルをダウンロードする。
2: BluemixのCatalogから、使いたいSpeech to Text機能を検索して選択
Speech to Textの検索画面
Speech to Textの説明ページの右下「Create」をクリックする
(クレジットカードを登録していない場合 ここでinvalid account typeというエラーが出る)
3:ターミナルからcurlでWatsonへアクセス
ターミナルへ入力
$ curl -X POST -u ここにusername:ここにpassword --header "Content-Type: audio/flac" --header "Transfer-Encoding: chunked" --data-binary @audio-file.flac "https://stream.watsonplatform.net/speech-to-text/api/v1/recognize"
(curl: no URL specified! curl: try 'curl --help' or 'curl --manual' for more informationなどのエラーがでた場合、curlコマンドの中の空白スペースが2つ以上でないか調べる)
成功した場合の結果:
ターミナルに、デモデータの音声を文字にした以下の文字列が現れる。
{
"results": [
{
"alternatives": [
{
"confidence": 0.891,
"transcript": "several tornadoes touch down as a line of severe thunderstorms swept through Colorado on Sunday "
}
],
"final": true
}
],
"result_index": 0
}%
日本語対応の場合:
$ curl -X POST -u ここにusername:ここにpassword --header "Content-Type: audio/flac" --header "Transfer-Encoding: chunked" --data-binary @audio-file.flac "https://stream.watsonplatform.net/speech-to-text/api/v1/models/ja-JP_BroadbandModel/recognize"
テストデータ&参考:IBM THINK Watson - Watsonにテープ起こしさせてみた - Japan
音声データ:「ただいまワトソンのテスト 中。本日は晴天なり。本日は晴天なり」
出力結果:
{
"results": [
{
"alternatives": [
{
"confidence": 0.73,
"transcript": "ただいま ワトソン の テスト 中 長芋 と その テスト 中 の 日 は 晴天 なり の 日 は 晴天 なり "
}
],
"final": true
}
],
"result_index": 0
}%