目的
Bing Speech APIを、テスト目的で使ってみたい。
大体curlを使うらしいけど、もっと手軽に(Windows環境で他のソフトをインストールせずに)試してみたい。
やりかた
Invoke-RestMethodコマンドレットを使う。
Power Shell 4.0で動作確認。
Invoke-RestMethod -Uri "https://speech.platform.bing.com/speech/recognition/conversation/cognitiveservices/v1?language=ja-JP&format=detailed" -Method POST -ContentType "audio/wav; codec=audio/pcm; samplerate=8000" -Headers @{"Transfer-Encoding" = "chunked";"Ocp-Apim-Subscription-Key" = "APIキーをここに指定"} -InFile "C:\Users\username\desktop\音声ファイル.wav" -OutFile "C:\Users\username\desktop\認識結果.json"
- samplerate
- APIキー
- InFile
- OutFile
の4つを書き換えれば、とりあえず動く・・・はず。
結果
こんな感じのjsonが取れます。
認識結果.json
{"RecognitionStatus":"Success","Offset":1600000,"Duration":58800000,"NBest":[{"Confidence":0.5427112,"Lexical":"本日は晴天なり","ITN":null,"MaskedITN":null,"Display":"本日は晴天なり"},{"Confidence":0.5427112,"Lexical":"本日は晴天なり","ITN":null,"MaskedITN":null,"Display":"本日は晴天なり"},{"Confidence":0.5427112,"Lexical":"本日は晴天なり","ITN":null,"MaskedITN":null,"Display":"本日は晴天なり"},{"Confidence":0.542555034,"Lexical":"本日は晴天なり","ITN":null,"MaskedITN":null,"Display":"本日は晴天なり"},{"Confidence":0.542555034,"Lexical":"本日は晴天なり","ITN":null,"MaskedITN":null,"Display":"本日は晴天なり"}]}
参考にさせていただいたページ
Bing Speech APIで音声ファイルをテキスト化してChatworkに投稿してみました。
https://dev.classmethod.jp/cloud/bing-speech-api/
Windowsにcurlが無い?いいえ、Invoke-RestMethodがあります。GrailsアプリへのPOSTリクエストを試す
https://qiita.com/_y_u_/items/94dd8ad6fcc8d278f433