Open SAAD0206 opened 1 week ago
It states that the source is used outside of the with scope. Are you sure that the try/except block and the rec.listen(source) are inside the "with" block? Its just unclear because of the formatting on github :0
I have it like this and it works.
import pyttsx3
import speech_recognition as sr
engine = pyttsx3.init("sapi5")
voices = engine.getProperty("voices")
def speak(audio):
engine.say(audio)
print(audio)
engine.runAndWait()
def take_command():
rec = sr.Recognizer()
with sr.Microphone() as source:
print("listening")
rec.pause_threshold = 1
audio = rec.listen(source)
try:
print("RECOGNIZING...")
words = rec.recognize_google(audio,language="en-in")
print(f"user said: {words}")
except Exception as exp:
speak("say that again please...")
return "none"
return words
if __name__ == "__main__":
take_command()
@JeziahAnon Thanks. I added python syntax highlight
@SAAD0206 Please check JeziahAnon's reply
Expected behaviour
it should be listening my voice command
Actual behaviour
System information
(Delete all the statements that don't apply.)
My system is. (For example, "Ubuntu 16.04 LTS x64", "Windows 10 x64", or "macOS Sierra".)
My Python version is. (You can check this by running
python -V
.)My Pip version is. (You can check this by running
pip -V
.)My SpeechRecognition library version is. (You can check this by running
python -c "import speech_recognition as sr;print(sr.__version__)"
.)My PyAudio library version is / I don't have PyAudio installed. (You can check this by running
python -c "import pyaudio as p;print(p.__version__)"
.)My microphones are: (You can check this by running
python -c "import speech_recognition as sr;print(sr.Microphone.list_microphone_names())"
.)My working microphones are: (You can check this by running
python -c "import speech_recognition as sr;print(sr.Microphone.list_working_microphones())"
.)I installed PocketSphinx from. (For example, from the Debian repositories, from Homebrew, or from the source code.)