Python3を使って音声認識(Ubuntu)
ハーバード大学の CS50 に音声認識プログラムの紹介がある。
(参考)
CS50 for Japanese: コンピュータサイエンスの入門 – Week6
https://cs50.jp/x/2021/week6/
2:32:00 あたり
素材は以下。
https://cdn.cs50.net/2021/fall/lectures/6/src6/6/speech/
(このサンプルは CS50 の2022年版ではなくなっている)
動作させるには、以下のようにライブラリを追加する必要がある。
SpeechRecognition
$ python3 -m pip install SpeechRecognition
…
Installing collected packages: SpeechRecognition
Successfully installed SpeechRecognition-3.9.0
PyAudio のコンパイルのために、port-audio.h が必要。
portaudio19-dev
$ sudo apt install portaudio19-dev
PyAudio
$ python3 -m pip install PyAudio
Installing collected packages: PyAudio
Successfully installed PyAudio-0.2.13
サンプルコード
listen1.py
# Recognizes a voice
# https://pypi.org/project/SpeechRecognition/
import speech_recognition
# Obtain audio from the microphone
recognizer = speech_recognition.Recognizer()
with speech_recognition.Microphone() as source:
print("Say something:")
audio = recognizer.listen(source)
# Recognize speech using Google Speech Recognition
print("You said:")
print(recognizer.recognize_google(audio))
カテゴリー: memo, Python, Python3
タグ: port-audio.h, PyAudio, speech, speech-recognition
カウント: 229