Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
203 views
in Technique[技术] by (71.8m points)

python - Raspberry Pi speech recognition with Google has errors

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Could you try Houndify or Wit.ai (sometimes the default recognize google has problems)? Both are free. As for it freezing it could be because your mic isn't working. Or it could be you need to set a time limit for r.listen().

audio = r.listen(source,timeout=4,phrase_time_limit=4)

If that doesn't work try:

r.record(source,duration=time)

The difference(i think) is that the first one uses VAD. VAD = voice activity detection which does exactly what it sounds like. The problem occurs when the VAD in r.listen() never gets triggered. This causes it to never start recording. If neither of these work it is probably a problem with your mic. You could also look into the module's energy threshold. Like this:

r.energy_threshold = 300 #mess around with the number and see what works.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...