0

So I get an error like the following:

     Traceback (most recent call last):
      File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\lib\site-packages\speech_recognition\__init__.py", line 108, in get_pyaudio
        import pyaudio
    ModuleNotFoundError: No module named 'pyaudio'
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "C:\Users\pc\Desktop\lerconn.py", line 3, in <module>
        with spr.Microphone() as mic:
      File "C:\Users\pc\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\pc\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

with a basic speech/sound recognition system:

    import speech_recognition as spr
    with spr.Microphone() as mic:
        try:
            audin = rec.recognize_google(rec.listen(mic), language="tr-TR")
            print(audin)
        except spr.UnknownValueError:
            # response= rand(notexisterrors)
             response = "I don't currently know the word or the phrase."
            
        except spr.RequestError:
            # response = rand(reqerrors)
              response = "Some weird problems with your system."
        else:
            # response = rand(unknownerrors)
             response = "Unknown error, I don't get it."
        print(response)

I tried pip install'ing PyAudio looking at the error, but that didn't work either.

I use: Python 3.8.5 - Text Editor(s): Notepad, Notepad++ and IDLE - OS: Windows 10 Pro 64 Bit

Feel free to ask anything. Thanks in advance!

LercDsgn
  • 131
  • 12
  • What do you use to run the code? Is there a possibility it's a different Python environment than the one you ran `pip` in? – Random Davis Oct 02 '20 at 16:47
  • Does this help? https://stackoverflow.com/questions/55984129/attributeerror-could-not-find-pyaudio-check-installation-cant-use-speech-re Run: pip install pipwin Then: pip install PyAudio – Grebtsew Oct 02 '20 at 16:50
  • @RandomDavis As I remember, all other "pip installed" modules I already tried works fine. But yes, there does be a possibility. Thanks! – LercDsgn Oct 02 '20 at 17:21

1 Answers1

0

I got the ModuleNotFoundError: No module named 'pyaudio' message when trying to run your example with the SpeechRecognition package installed only. It seems to be working if you complement with pipwin and pyaudio.

Install by running:

pip install SpeechRecognition 
pip install pipwin   # Windows
pipwin install pyaudio

Then I had a small issue with finding correct mic index but this works for me:

import speech_recognition as spr

rec = spr.Recognizer()

# Show all available microphones in system
for index, name in enumerate(spr.Microphone.list_microphone_names()):
   print("Microphone with name \"{1}\" found for `Microphone(device_index={0})`".format(index, name))

# set correct mic
i = 0

response = "It worked!"

with spr.Microphone(device_index=i) as mic: 
   audio = rec.listen(mic, phrase_time_limit=5) # 5 s timer
try:
   
   audin = rec.recognize_google(audio, language="en-US")
   print(audin) # Show result
except spr.UnknownValueError:
   response = "I don't currently know the word or the phrase "
   
except spr.RequestError:
   response = "Some weird prolems with your system."
except Exception as e:
   response = "Error:" + str(e)
   response = "There is some unknown error, dude. I don't get it. Sorry."
else:
   print(response)
Grebtsew
  • 192
  • 5
  • 13
  • It seems to be working, but what I wonder is if it doesn't print anything after the list of microphones - the for loop- and waits with the "|" sign blinking, which I guess means "waiting for input/loading"; is there a problem with the microphone? Like, it can't get an input from the mic., so it just keeps waiting for different values? – LercDsgn Oct 02 '20 at 17:49
  • Yes, that sounds like a familiar symtom. Try changing the mic index. The phrase_time_limit should limit the recorded sound from mic to 5 seconds, so when it is working correctly the execution should be around 5 seconds. If it couldn't find any words it should end with "It worked!". You can try removing the device_index parameter too. – Grebtsew Oct 02 '20 at 18:39