You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AssertionError: Audio source must be entered before listening, see documentation for AudioSource; are you using source outside of a with statement?
#765
Open
SAAD0206 opened this issue
Sep 5, 2024
· 2 comments
importpyttsx3importspeech_recognitionassrengine=pyttsx3.init("sapi5")
voices=engine.getProperty("voices")
# text to speechdefspeak(audio):
engine.say(audio)
print(audio)
engine.runAndWait()
deftake_command():
rec=sr.Recognizer()
withsr.Microphone() assource:
print("listening")
rec.pause_threshold=1audio=rec.listen(source)
try:
print("RECOGNIZING...")
words=rec.recognize_google_cloud(audio,language="en-in")
print(f"user said: {words}")
exceptExceptionasexp:
speak("say that again please...")
return"none"returnwordsif__name__=="__main__":
take_command()
#speak("MY NAME IS JARVIS I AM HERE TO ASSIST U")
(How do you make the issue happen? Does it happen every time you try it?) every time i run this code
(Make sure to go into as much detail as needed to reproduce the issue. Posting your code here can help us resolve the problem much faster!)
(If there are any files, like audio recordings, don't forget to include them.)
Expected behaviour
it should be listening my voice command
Actual behaviour
'NoneType' object has no attribute 'close'
File "C:\Users\atif\Documents\PYTHON\JARVIS.py", line 20, in take_command
audio = rec.listen(source)
^^^^^^^^^^^^^^^^^^
AssertionError: Audio source must be entered before listening, see documentation for ``AudioSource``; are you using ``source`` outside of a ``with`` statement?
During handling of the above exception, another exception occurred:
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.)
The text was updated successfully, but these errors were encountered:
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
ftnext
changed the title
python error
AssertionError: Audio source must be entered before listening, see documentation for AudioSource; are you using source outside of a with statement?
Sep 15, 2024
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.)
The text was updated successfully, but these errors were encountered: