0

I am using python 3.8. I was building a jarvis using a youtube video all was working fine until I use speech recognition package. It is just saying good afternoon sir after that it is showing an error which is:

Traceback (most recent call last):
  File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\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\Dell\Desktop\123.py", line 48, in <module>
    query = takeCommand().lower()
  File "c:\Users\Dell\Desktop\123.py", line 28, in takeCommand
    with sr.Microphone() as source:
  File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\lib\site-packages\speech_recognition\__init__.py", line 79, in __init__
    self.pyaudio_module = self.get_pyaudio()
  File "C:\Users\Dell\AppData\Local\Programs\Python\Python38\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

Even I have tried to install pyaudio which is even showing error.


import pyttsx3
import speech_recognition as sr
import datetime
import wikipedia
import webbrowser

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)


def speak(audio):
    engine.say(audio)
    engine.runAndWait()

def wishMe():
    hour = int(datetime.datetime.now().hour)
    if hour>=0 and hour<12:
        speak('Good Morning Sir')
    elif hour>=12 and hour<18:
        speak('Good Afternoon sir')
    else:
        speak('Good Evening sir')    

    speak('I am Jarvis')   
def takeCommand():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print('Listening...')
        r.pause_threshold = 1
        audio = r.listen(source)

    try:
        print('Recognizing...')
        query = r.recognize_google(audio, language='en')
        print(f"User said: {query}\n")

    except Exception as e:

        print('say that again pls sir')
        return "None"
    return query       


if __name__ == "__main__":
   wishMe()
   while True:
        query = takeCommand().lower()
   #executing task based on query


        if 'wikipedia' in query:
            speak('Searching wikipedia')
            query = query.replace("wikipedia", "")
            results = wikipedia.summary(query, sentences=2)
            speak("According to Wikipedia")
            speak(results)

        elif 'open YouTube' in query:
            webbrowser.open_new_tab("https:\\www.youtube.com")
Roshin Raphel
  • 2,612
  • 4
  • 22
  • 40
destro
  • 11
  • 1
  • 3
  • you have to install module `PyAudio` – furas Jul 01 '20 at 19:18
  • [I can't install pyaudio on Windows? How to solve “error: Microsoft Visual C++ 14.0 is required.”?](https://stackoverflow.com/questions/52283840/i-cant-install-pyaudio-on-windows-how-to-solve-error-microsoft-visual-c-14) - it is different error but probably it shows solution - install precompiled module from [Unofficial Windows Binaries for Python Extension Packages](https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio) – furas Jul 01 '20 at 19:23

3 Answers3

0

You need to install pyaudio by going to https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio and you will find many pyaudio wheels.

  • Download the first one #do not change the name of the file,,
  • open command prompt,
  • use cd to go to the directory where your wheel has been installed,
  • then use pip install (name of file) #use .whl as well

if it doesn't work, download the second one and repeat the process, if that doesn't work as well, keep on downloading until I guarantee you that at least one of them would be installed in your computer

Ahmad Waqar
  • 474
  • 4
  • 7
-1

use this and thanks me later:

!pip install pipwin

!pipwin install pyaudio

it will definitely work

David
  • 15,894
  • 22
  • 55
  • 66
-1

Firstly , The Python version 3.8 doesn't support PyAudio so you have to download from other source and i have given link from where you can download the pyaudio:

https://www.lfd.uci.edu/~gohlke/pythonlibs/

after opening the link search for pyaudio in the webpage then click on it and there will be a list of pyaudio files according to your python version select this given file name .

Download this for 64 bit device - PyAudio‑0.2.11‑cp38‑cp38‑win_amd64.whl

Download this for 32 bit device - PyAudio‑0.2.11‑cp38‑cp38‑win32.whl

After this open the command prompt and copy the path where the downloaded the pyaudio file is save ...

write the command in cmd : pip install <paste the downloaded pyaudio file name> >>

Now you can continue with your code and hope error will be solved !

Zeeking786
  • 165
  • 1
  • 27