先人に感謝
キーワード: 音声認識, Google API, Python, SpeechRecognition
システム Python を使うことができる(その場合,Python のインストールは行わない)
システム Python を用いるときは,pip, setuptools の更新は次のコマンドで行う.
sudo apt -y update sudo apt -y install python3-pip python3-setuptools
Ubuntu で,システム Python 以外の Python をインストールしたい場合は pyenv が便利である: 別ページで説明している.
Python の URL: http://www.python.org/
【Python, pip の使い方】
Python, pip は,次のコマンドで起動できる.
【Python 開発環境のインストール】
JupyterLab, spyder, nteract (Python 開発環境) のインストールは, Windows でコマンドプロンプトを管理者として実行し, 次のコマンドを実行.
python -m pip install -U pip setuptools jupyterlab jupyter jupyter-console jupytext nteract_on_jupyter spyder
詳しくは,: 別ページで説明している.
JupyterLab, spyder, nteract (Python 開発環境) のインストール: : 別ページで説明している.
※ Windows では「python」,Ubuntu では「sudo python3 -m pip」
python -m pip install -U SpeechRecognition
引き続き,次のコマンドを実行
pip install -U pyaudio
※ 手元に .wav ファイルがないよ,というときは http://www.wavsource.com(インターネットでは,下品な広告が付いている可能性があるので,必要もないのにクリックしないこと) などから入手できる(.wav ファイルをダウンロードするときは、利用条件などを確認すること)
Python プログラムを動かすために, Windows では「python」, Ubuntu では「python3」などのコマンドを使う.
あるいは, 開発環境や Python コンソール(Jupyter Qt Console,Spyder,PyCharm,PyScripter など)の利用も便利である.
あるいは,オンラインで動くGoogle Colaboratory のノートブックの利用も,場合によっては便利である.
import os print(os.getcwd())
実行結果例
次の Python プログラムを実行
「"coincidence.wav" 」のところは,ファイル名を書き換えること.
import speech_recognition
r = speech_recognition.Recognizer()
with speech_recognition.AudioFile("coincidence.wav") as source:
audio = r.record(source)
r.recognize_google(audio)
実行結果の例
次の Python プログラムを実行
「"1.wav" 」のところは,ファイル名を書き換えること.
import speech_recognition
r = speech_recognition.Recognizer()
with speech_recognition.AudioFile("1.wav") as source:
audio = r.record(source)
r.recognize_google(audio, language='ja-JP')
実行結果の例