Speech Recognition with Python3
### main.py
```
# https://www.codesofinterest.com/2017/03/python-speech-recognition-pocketsphinx.html
import speech_recognition as sr
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Please wait. Calibrating microphone...")
r.adjust_for_ambient_noise(source, duration=5)
while 1:
print("\nSay something!")
audio = r.listen(source)
# recognize speech using Sphinx
try:
#print("Google thinks you said '" + r.recognize_google(audio, language="zh-CN") + "'")
print("Sphinx thinks you said '" + r.recognize_sphinx(audio, language="en-US") + "'")
except sr.UnknownValueError:
print("Sphinx could not understand audio")
except sr.RequestError as e:
print("Sphinx error; {0}".format(e))
```
_______________________________________________________
### install_requirements.sh
```
sudo pip3 install pocketsphinx
sudo pip3 install SpeechRecognition
sudo apt-get install python3-pyaudio
```
______________________________________________________
### author
yingshaoxo
```
# https://www.codesofinterest.com/2017/03/python-speech-recognition-pocketsphinx.html
import speech_recognition as sr
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Please wait. Calibrating microphone...")
r.adjust_for_ambient_noise(source, duration=5)
while 1:
print("\nSay something!")
audio = r.listen(source)
# recognize speech using Sphinx
try:
#print("Google thinks you said '" + r.recognize_google(audio, language="zh-CN") + "'")
print("Sphinx thinks you said '" + r.recognize_sphinx(audio, language="en-US") + "'")
except sr.UnknownValueError:
print("Sphinx could not understand audio")
except sr.RequestError as e:
print("Sphinx error; {0}".format(e))
_______________________________________________________
### install_requirements.sh
```
sudo pip3 install pocketsphinx
sudo pip3 install SpeechRecognition
sudo apt-get install python3-pyaudio
```
______________________________________________________
### author
yingshaoxo