0
0

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.

(windows用補足)python3でGoogle Cloud Speech-to-Text APIでリアルタイム音声認識する

0
Last updated at Posted at 2019-08-13

参考:
https://qiita.com/yoshiokaCB/items/9e2e968756beb53fa452
https://qiita.com/sayonari/items/4656212b4d34714ab98f
https://qiita.com/fiftystorm36/items/b2fd47cf32c7694adc2e
https://techacademy.jp/magazine/20860

誠にありがたいことに、99%は参考欄にある先人の方々のMacのコードで動きました。

pythonの初歩的な知識が無いまま、無理にwindowsで音声認識しようとし、エラーが発生したので、その記録を残します。

上記リンクを参考に、cloudSDKの準備、APIを使うためのjsonファイルを用意し、サンプルコードをgit cloneした後、

# ライブラリインポート
pip install google
pip install google.cloud
pip install google.cloud.speech
pip install grpc-google-cloud-speech-v1beta1
pip install pyaudio

# 仮想環境
virtualenv venv
env\Scripts\activate

# 環境変数
set GOOGLE_APPLICATION_CREDENTIALS=C:\Users\xxx\Downloads\xxxxxxxx.json

# 音声認識
cd C:\Users\xxx\python-docs-samples\speech\cloud-client
transcribe_streaming_mic.py


PCに向かってしゃべると音声認識してくれる。超すごい。

躓いたポイント
1.windowsの仮想環境

env\Scripts\activate

(仮想環境にしないとcannot import enumsのエラーが出ました。「仮想環境で実行しろ」のエラーではないので、一生懸命enumsのライブラリをインストールしましたが、解決できません(解決策はstack overflowにあり)。先人たちのサンプルはMacのコードで、windowsの仮想環境のコマンドがわからず、早く動かしたくて仮想環境に入るのを無視してたら、このエラーで躓きました。)

2.環境変数の設定

set GOOGLE_APPLICATION_CREDENTIALS=C:\Users\xxx\Downloads\xxxxxxx.json

(ディレクトリとファイル名は""や''や<>で括らないで、そのまま書く。参考にしたコードが括られていて、そこに気づかずに躓いた。Windowsだけかしら?)

3.マイク入力をON
以下の手順でミュートを解除する(やっと動いたコードが動かなくなった?と焦ったのはこの初歩的ミスだった。)
コントロールパネル→サウンド→録音→マイク(マイク配列?)→プロパティ→レベル

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?