I have two projects for speech recognition using RP3 and Google .. the first is to retrieve the text from google and send it to mobile application .. the other is to control a mouse pointer with the speech
I have an old version of Raspbian (Noobs) .. I flashed the system to a 16 MB memory card then started the RP3
I made update and upgrade for the system using
sudo apt update
sudo apt upgrade
I attached my USB microphone and tested the sound gain
arecord -l
aplay -l
arecord -D plughw:1,0 -d 3 test.wav && aplay test.wav
alsamixer
Then based on the web site https://pythonspot.com/speech-recognition-using-google-speech-api/ I installed the libraries:
git clone http://people.csail.mit.edu/hubert/git/pyaudio.git
cd pyaudio
sudo python setup.py install
sudo python3 setup.py install
sudo apt-get install libportaudio-dev
sudo apt-get install python-dev
sudo apt-get install python3-dev
sudo apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev
sudo pip3 install SpeechRecognition
Then I tried the code mentioned in the website .. sometimes I got error and other times the output is (Say Something) then freeezes
#!/usr/bin/env python3
# Requires PyAudio and PySpeech.
import speech_recognition as sr
# Record Audio
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)
# Speech recognition using Google Speech Recognition
try:
# for testing purposes, we're just using the default API key
# to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
# instead of `r.recognize_google(audio)`
print("You said: " + r.recognize_google(audio))
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
Thanks for your answers and help
question from:
https://stackoverflow.com/questions/65682146/raspberry-pi-speech-recognition-with-google-has-errors 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…