Hey everyone, I was trying to make a script using SpeechRecognition module. It identifies what the user tells and it prints the input
This is the script
import speech_recognition as sr
Recognition = sr.Recognizer()
with sr.Microphone() as source:
print("Please speak anything")
Listener = Recognition.listen(source)
try:
Spoken_Text = Recognition.recognize_google(Listener)
print("The user spoke: {}".format(Spoken_Text))
except:
print("Sorry could not recognize the test")
It is giving an error on line 5 that it:
with sr.Microphone() as source:
The error is:
Traceback (most recent call last):
File “c:/Users/--------/Desktop/Python projects/Speech recognition.py”, line 5, in
with sr.Microphone() as source:
File “C:\Users-----------\AppData\Local\Programs\Python\Python38-32\lib\site-packages\speech_recognition_init_.py”, line 79, in init
self.pyaudio_module = self.get_pyaudio()
File “C:\Users---------\AppData\Local\Programs\Python\Python38-32\lib\site-packages\speech_recognition_init_.py”, line 110, in get_pyaudio
raise AttributeError(“Could not find PyAudio; check installation”)
AttributeError: Could not find PyAudio; check installation
PS C:\Users------\Desktop\Python projects>
Can’t send screenshot as someone in my previous post said it is not safe to post screenshots for errors
Hello, @PythonBoy. As error also says, you must install the pyaudio module; because microphone input requires it. You can easily install it by typing pip install PyAudio to your terminal window.
Requirements Which Were Mentioned At SpeechRecognition · PyPI :
To use all of the functionality of the library, you should have:
Python 2.6, 2.7, or 3.3+ (required)
PyAudio 0.2.11+ (required only if you need to use microphone input, Microphone)
PocketSphinx (required only if you need to use the Sphinx recognizer, recognizer_instance.recognize_sphinx)
Google API Client Library for Python (required only if you need to use the Google Cloud Speech API, recognizer_instance.recognize_google_cloud)
FLAC encoder (required only if the system is not x86-based Windows/Linux/OS X)
The following requirements are optional, but can improve or extend functionality in some situations:
On Python 2, and only on Python 2, some functions (like recognizer_instance.recognize_bing) will run slower if you do not have Monotonic for Python 2 installed.
If using CMU Sphinx, you may want to install additional language packs to support languages like International French or Mandarin Chinese.
PyAudio page at PyPI : PyAudio · PyPI
Note: You don’t have to worry about these requirements if interpreter doesn’t give any error about them.
Thanks for the help @soil. That’s what I thought that there was no error in the script but in the module, but I did not know which module was missing. Really thanks for the help!
From PyAudio · PyPI, it is evident that already-built packages are available only for Python 2.7 through 3.6. If you have a later version, doing pip install pyaudio will try to build from source, which requires a build environment, which can be a challenge to set up. To avoid this, you can try downloading pyaudio from Python Extension Packages for Windows - Christoph Gohlke, which has already-built wheels for later versions of Python.
Hey, Looks like I’m the unluckiest amongst all the users. Sure I will download it. But is there any additional setup needed to be done? or after installing it then can I use cmd?
True, in the past, I try to install Microsoft Build Tools, and it’s very hard to understand which tool/extension need to install. @adang1345 comment shows the easy way without you need to download other tools except the wheel itself.
But, typing pip install PyAudio says system to install PyAudio from its web source. @gunungpw has already mentioned about setting up modules via local files, in this topic. You can use any of the four methods :
py -m pip install --no-index --find-links=file:///local/dir/ SomePackage
OR
py -m pip install --no-index --find-links=/local/dir/ SomePackage
OR
py -m pip install --no-index --find-links=relative/dir/ SomePackage
OR
pip install some-package.whl
The PyPI website’s pip did not work so I planned to download it from the website that @gunungpw suggested. I was just wondering which one of them to download