Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

I am currently working with python 3.8. I was forming a Jarvis using a tutorial video and all was operating fine until I use the speech recognition package. It is just displaying good afternoon sir message 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'

When I was checking the above exception, another error 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

#I have also installed 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")

1 Answer

0 votes
by (108k points)

I think that you have not installed the package in the correct manner, Kindly use the below code that will help you to install the necessary packages in your python environment:

!pip install pipwin

!pipwin install pyaudio

Kick-start your career in Python with the Intellipaat's perfect Python Course now!

 

Browse Categories

...