Answer the question
In order to leave comments, you need to log in
How to solve the problem with the speech_recognition library when recognizing speech on Ubuntu OS?
The code
import speech_recognition as sr
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)
# recognize speech 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("Google Speech Recognition thinks 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))
r.listen(source)
, the program should receive sound from the microphone, but does not. sr.Microphone(device_index=int) # вместо int указывал индекс звукового устройства
Answer the question
In order to leave comments, you need to log in
Look here - Linux: ALSA lib pcm_dmix.c:1108:(snd_pcm_dmix_open...
Or try running the script with sudo, maybe you don't have any rights.
Or try adding your user to the audio group, or whatever else is there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question