Currently I'm trying to have the speech_recognition module listen in the background when the user pushes a button made with py qt. I have the initialization and callback methods in a class, however when I try and listen to the microphone it doesn't seem to be registering anything, not even outputting errors.
import time
import speech_recognition as sr
def callback(recognizer, audio):
try:
print("Google Speech Recognition thinks you said " + recognizer.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))
r = sr.Recognizer()
m = sr.Microphone()
with m as source:
r.adjust_for_ambient_noise(source)
stop_listening = r.listen_in_background(m, callback)
for _ in range(50): time.sleep(0.1)
stop_listening(wait_for_stop=False)
while True: time.sleep(0.1) ```
i want data to be sent the response as soon as it hears a word. the response need to be printed in the console
So, from what I gather, you copied this example https://github.com/Uberi/speech_recognition/blob/master/examples/background_listening.py
Now you are asking why it does not work for you.
At the top of the example, it is noted: "# NOTE: this example requires PyAudio because it uses the Microphone class"
Do you have PyAudio installed?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.