0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PowerShellからAzureのBing Speech APIを呼び出すテスト

Posted at

目的

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

0
2
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?