WebSocket Service
この項では音声認識の WebSocket API について述べます。
接続情報
-
mimi ASR
URL: wss://asr.mimi.fd.ai/v1/recognize/fairy -
mimi ASR powered by NICT
URL: wss://asr.mimi.fd.ai/v1/recognize/nict -
Google™ Cloud Speech-to-Text
URL: wss://asr.mimi.fd.ai/v1/recognize/google
概要
音声認識 の WebSocket API では、以下のサービスが利用できます。
- mimi ASR: 日本語音声認識
- mimi ASR powered by NICT: 多言語音声認識 ( NICT )
- Google™ Cloud Speech-to-Text: 多言語音声認識( Google API 連携 ※ 別途契約が必要)
リクエストのパラメータは HTTP リクエストヘッダとして送ってください。
mimi の WebSocket API サービス利用について詳しくは mimi WebSocket API サービス を参照ください。
音声認識は、入力音声に対して認識した結果(=応答)を JSON 形式で受け取ることができます。
その JSON 形式の応答の構成と応答取得回数は、利用するサービスによって異なります。
詳しくは後述の "API Reference" および "応答例" を参照ください。
認証
WebSocket APIサービスをご利用の際には実行したいサービスに対応するスコープ( スコープ一覧 )を指定して発行したアクセストークンが必要です。
mimi API Console 画面からの操作で取得するには トークンの取得 を参照ください。
APIの実行で取得するには 認証/認可操作 を参照ください。
クエリ文字列でのリクエスト
ブラウザ上で WebSocket API を利用する場合等、 HTTP ヘッダを使った実行時設定の指定ができない場合は、 HTTP ヘッダの代わりにクエリ文字列を使って実行時設定を指定することができます。
クエリ文字列による HTTP ヘッダの代替 の記述を参照ください。
API Reference
音声認識 API の詳細な情報については、API Reference を参照ください。
- 音声認識( mimi ASR API )を行う
- 音声認識( mimi ASR powered by NICT API )を行う
- 音声認識( Google™ Cloud Speech-to-Text API )を行う
実行
以下は mimi.example.python の mimi ASR サンプルスクリプト asr_stream_file.py、mimi ASR powered by NICT(ここでは ASR-NICT と略記)サンプルスクリプト asr_nict_stream_file.py を使用した WebSocket サービスの利用例です。
実行例
下記のタブ切り替えで mimi ASR 、ASR-NICTの実行例を確認できます。
# mimi ASR の応答を得ます。
python3 asr_stream_file.py token.txt audio.raw# v2 フォーマットで最終結果を得ます。
#
# カスタムヘッダにて以下を指定した場合と同様のリクエストを実行することになります。
# x-mimi-nict-asr-options: response_format=v2;progressive=false;temporary=false;
python3 asr_nict_stream_file.py token.txt audio.raw# v2 フォーマットで一時結果あり、部分結果なしの応答を得ます。
#
# カスタムヘッダにて以下を指定した場合と同様のリクエストを実行することになります。
# x-mimi-nict-asr-options: response_format=v2;progressive=false;temporary=true;
python3 asr_nict_stream_file.py token.txt audio.raw --temporary# v2 フォーマットで一時結果あり、部分結果ありの応答を得ます。
#
# カスタムヘッダにて以下を指定した場合と同様のリクエストを実行することになります。
# x-mimi-nict-asr-options: response_format=v2;progressive=true;temporary=true;
python3 asr_nict_stream_file.py token.txt audio.raw --progressive --temporary# v1 フォーマットで応答を得ます。
#
# カスタムヘッダにて以下を指定した場合と同様のリクエストを実行することになります。
# x-mimi-nict-asr-options: response_format=v1
python3 asr_nict_stream_file.py token.txt audio.raw -f v1応答例
下記のタブ切り替えで mimi ASR 、ASR-NICT の応答例とその構成内容についての簡易な説明を確認できます。
# 応答 JSON の要素
# "response" : 応答配列(認識結果は配列で返されます),
# "pronunciation" : 認識結果のテキストの発音
# "result" : 認識結果のテキスト
# "time" : 開始時刻と終了時刻(音声データの始点を起点とした時刻(ミリ秒))
# "session_id" : セッションID
# "status" : 音声認識のステータス
# "type" : 音声認識の型
#
{ "response" : [
{
"pronunciation" : "チョット",
"result" : "ちょっと",
"time" : [ 1350, 1800 ]
}, {
"pronunciation" : "オソイ",
"result" : "遅い",
"time" : [ 1800, 2160 ]
} ],
"session_id" : "f7f10c90-e661-11e9-8f10-42010a9200a5",
"status" : "recog-in-progress",
"type" : "asr#mimilvcsr"
}
:
// (中略) : 認識処理途中で複数回応答が返ってくる
:
{
"response" : [
{
"pronunciation" : "チョット",
"result" : "ちょっと",
"time" : [ 1350, 1800 ]
}, {
"pronunciation" : "オソイ",
"result" : "遅い",
"time" : [ 1800, 2170 ]
}, {
"pronunciation" : "チューショク",
"result" : "昼食",
"time" : [ 2170, 2730 ]
}, {
"pronunciation" : "ヲ",
"result" : "を",
"time" : [ 2730, 2850 ]
}, {
"pronunciation" : "トル",
"result" : "とる",
"time" : [ 2850, 3090 ]
}, {
"pronunciation" : "タメ",
"result" : "ため",
"time" : [ 3090, 3370 ]
}, {
"pronunciation" : "ニ",
"result" : "に",
"time" : [ 3370, 3480 ]
}, {
"pronunciation" : "ファミリー",
"result" : "ファミリー",
"time" : [ 3480, 4000 ]
}, {
"pronunciation" : "レストラン",
"result" : "レストラン",
"time" : [ 4000, 4530 ]
}, {
"pronunciation" : "ニ",
"result" : "に",
"time" : [ 4530, 4620 ]
}, {
"pronunciation" : "ハイッ",
"result" : "入っ",
"time" : [ 4620, 4960 ]
}, {
"pronunciation" : "タ",
"result" : "た",
"time" : [ 4960, 5060 ]
}, {
"pronunciation" : "ノ",
"result" : "の",
"time" : [ 5060, 5180 ]
}, {
"pronunciation" : "デス",
"result" : "です",
"time" : [ 5180, 5630 ]
}
],
"session_id" : "f7f10c90-e661-11e9-8f10-42010a9200a5",
"status" : "recog-finished",
"type" : "asr#mimilvcsr"
}# 以下の JSON は、カスタムヘッダにて以下を指定した場合のサンプルです。
# x-mimi-nict-asr-options: response_format=v2;progressive=false;temporary=false
#
# 途中結果はなく、最終結果のみが返ります。
#
# 応答 JSON の要素
# "response" : 応答配列(認識結果は配列で返されます),
# "result" : 認識結果のテキスト
# "determined" : 確定した結果かどうか
# "time" : 該当応答の発話中における開始時刻(ミリ秒)
# "session_id" : セッションID
# "status" : 音声認識のステータス
# "type" : 音声認識の型
{
"type": "asr#nictlvcsr2",
"session_id": "d0375f52-a794-4776-bef5-ea301d84fcff",
"status": "recog-finished",
"response": [
{
"result": "ちょっと遅い昼食をとるため、ファミリーレストランに入ったのです",
"words": [
"ちょっと",
"遅い",
"昼食",
"を",
"とる",
"ため",
"ファミリーレストラン",
"に",
"入っ",
"た",
"の",
"です"
],
"determined": true,
"time": 570
}
]
}# 以下の一連のJSONは、カスタムヘッダにて以下を指定した場合のサンプルです。
# x-mimi-nict-asr-options: response_format=v2;progressive=false;temporary=true;temporary_interval=1500
#
# temporary=trueの指定をすると、最終結果より前に "未確定の音声認識結果の候補" が返ります。
# "未確定の音声認識結果の候補" とは、"determined": false の応答を指します。
#
# 応答 JSON の要素
# "response" : 応答配列(認識結果は配列で返されます),
# "result" : 認識結果のテキスト
# "determined" : 確定した結果かどうか
# "time" : 該当応答の発話中における開始時刻刻(ミリ秒)
# "session_id" : セッションID
# "status" : 音声認識のステータス
# "type" : 音声認識の型
{
"type": "asr#nictlvcsr2",
"session_id": "978966fc-286d-4779-a2f5-d460ab8914e5",
"status": "recog-in-progress",
"response": [
{
"result": "ちょっと",
"words": [
"ちょっと"
],
"determined": false,
"time": 0
}
]
}
{
"type": "asr#nictlvcsr2",
"session_id": "978966fc-286d-4779-a2f5-d460ab8914e5",
"status": "recog-in-progress",
"response": [
{
"result": "ちょっと遅い昼食をとる",
"words": [
"ちょっと",
"遅い",
"昼食",
"を",
"とる"
],
"determined": false,
"time": 0
}
]
}
{
"type": "asr#nictlvcsr2",
"session_id": "978966fc-286d-4779-a2f5-d460ab8914e5",
"status": "recog-in-progress",
"response": [
{
"result": "ちょっと遅い昼食をとるためファミリーレストランに",
"words": [
"ちょっと",
"遅い",
"昼食",
"を",
"とる",
"ため",
"ファミリーレストラン",
"に"
],
"determined": false,
"time": 0
}
]
}
{
"type": "asr#nictlvcsr2",
"session_id": "978966fc-286d-4779-a2f5-d460ab8914e5",
"status": "recog-in-progress",
"response": [
{
"result": "ちょっと遅い昼食をとるためファミリーレストランに入ったの",
"words": [
"ちょっと",
"遅い",
"昼食",
"を",
"とる",
"ため",
"ファミリーレストラン",
"に",
"入っ",
"た",
"の"
],
"determined": false,
"time": 0
}
]
}
{
"type": "asr#nictlvcsr2",
"session_id": "978966fc-286d-4779-a2f5-d460ab8914e5",
"status": "recog-finished",
"response": [
{
"result": "ちょっと遅い昼食をとるためファミリーレストランに入ったのです。",
"words": [
"ちょっと",
"遅い",
"昼食",
"を",
"とる",
"ため",
"ファミリーレストラン",
"に",
"入っ",
"た",
"の",
"です"
],
"determined": true,
"time": 0
}
]
}# 以下の一連のJSONは、カスタムヘッダにて以下を指定した場合のサンプルです。
# x-mimi-nict-asr-options: response_format=v2;progressive=true;temporary=true;temporary_interval=1500
#
# progressive=trueの指定をすると、最終結果より前に "確定した部分結果" が返ります。
# "確定した部分結果" とは "status": "recog-in-progress" 且つ "determined": true となる応答を指します。
#
# 応答 JSON の要素
# "response" : 応答配列(認識結果は配列で返されます),
# "result" : 認識結果のテキスト
# "determined" : 確定した結果かどうか
# "time" : 該当応答の発話中における開始時刻刻(ミリ秒)
# "session_id" : セッションID
# "status" : 音声認識のステータス
# "type" : 音声認識の型
{
"type": "asr#nictlvcsr2",
"session_id": "a36cf472-9afc-4b29-8353-04303604364e",
"status": "recog-in-progress",
"response": [
{
"result": "ちょっと",
"words": [
"ちょっと"
],
"determined": false,
"time": 0
}
]
}
{
"type": "asr#nictlvcsr2",
"session_id": "a36cf472-9afc-4b29-8353-04303604364e",
"status": "recog-in-progress",
"response": [
{
"result": "ちょっと遅い昼食をとる",
"words": [
"ちょっと",
"遅い",
"昼食",
"を",
"とる"
],
"determined": false,
"time": 0
}
]
}
{
"type": "asr#nictlvcsr2",
"session_id": "a36cf472-9afc-4b29-8353-04303604364e",
"status": "recog-in-progress",
"response": [
{
"result": "ちょっと遅い",
"words": [
"ちょっと",
"遅い"
],
"determined": true,
"time": 0
}
]
}
{
"type": "asr#nictlvcsr2",
"session_id": "a36cf472-9afc-4b29-8353-04303604364e",
"status": "recog-in-progress",
"response": [
{
"result": "昼食をとるためファミリーレストランに",
"words": [
"昼食",
"を",
"とる",
"ため",
"ファミリーレストラン",
"に"
],
"determined": false,
"time": 1380
}
]
}
{
"type": "asr#nictlvcsr2",
"session_id": "a36cf472-9afc-4b29-8353-04303604364e",
"status": "recog-in-progress",
"response": [
{
"result": "昼食をとるためファミリーレストランに入ったの",
"words": [
"昼食",
"を",
"とる",
"ため",
"ファミリーレストラン",
"に",
"入っ",
"た",
"の"
],
"determined": false,
"time": 1380
}
]
}
{
"type": "asr#nictlvcsr2",
"session_id": "a36cf472-9afc-4b29-8353-04303604364e",
"status": "recog-in-progress",
"response": [
{
"result": "昼食をとるためファミリーレストランに",
"words": [
"昼食",
"を",
"とる",
"ため",
"ファミリーレストラン",
"に"
],
"determined": true,
"time": 1380
}
]
}
{
"type": "asr#nictlvcsr2",
"session_id": "a36cf472-9afc-4b29-8353-04303604364e",
"status": "recog-finished",
"response": [
{
"result": "入ったのです。",
"words": [
"入っ",
"た",
"の",
"です"
],
"determined": true,
"time": 4140
}
]
}# 以下の JSON は、カスタムヘッダにて以下を指定した場合のサンプルです。
# x-mimi-nict-asr-options: response_format=v1
#
# 応答 JSON の要素
# "type" : 音声認識の型
# "session_id" : セッションID
# "status" : 音声認識のステータス
# "response" : 応答配列(認識結果は配列で返されます)
# "result" : 認識結果のテキスト | 認識結果のテキストの発音| ...(パイプ区切りの情報)
#
{
"type": "asr#nictlvcsr",
"session_id": "058720ce-e65d-11e9-ae3b-42010a92008f",
"status": "recog-finished",
"response": [
{
"result": "ちょっと|チョット|ちょっと|副詞-助詞類接続||||"
},
{
"result": "遅い|オソイ|遅い|形容詞-自立|形容詞・アウオ段|基本形||"
},
{
"result": "昼食|チュウショク|昼食|名詞-一般||||"
},
{
"result": "を|ヲ|を|助詞-格助詞-一般||||"
},
{
"result": "とる|トル|とる|動詞-自立|五段・ラ行|基本形||"
},
{
"result": "ため|タメ|ため|名詞-非自立-副詞可能||||"
},
{
"result": "ファミリーレストラン|ファミリーレストラン|ファミリーレストラン|名詞-一般||||"
},
{
"result": "に|ニ|に|助詞-格助詞-一般||||"
},
{
"result": "入っ|ハイッ|入る|動詞-自立|五段・ラ行|連用タ接続||"
},
{
"result": "た|タ|た|助動詞|特殊・タ|基本形||"
},
{
"result": "の|ノ|の|名詞-非自立-一般||||"
},
{
"result": "です|デス|です|助動詞|特殊・デス|基本形||"
},
{
"result": "|||SENT-START-END||||"
},
{
"result": "|||UTT-END||||"
}
]
}
サードパーティの WebSocket ライブラリを使う場合の注意
現時点では、 mimi サーバーは RFC6455 の 5.4 項の Fragmentation に対応しておりません。クライアントは fragmented frames を送信しないでください。
ASR の種類によって応答の形式やタイミングが異なります。WebSocket で mimi ASR を指定して音声認識を行う場合、指定の音声データの認識処理の途中経過のテキストをリアルタイムで取得することができます。WebSocket で mimi ASR powered by NICT を指定して音声認識を行う場合、認識処理が完了した後でテキストを取得することができます。
