Search code examples
pythonartificial-intelligence

pyaudio is not installing


hey there I am working a project JARVIS and when I ran my code It gave me a error no module named pyaudio. and when I tried installing It by typing pip install pyaudio It gave me error. I am on a windows machine(windows 7)

    Complete output (9 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.7
    copying src\pyaudio.py -> build\lib.win32-3.7
    running build_ext
    building '_portaudio' extension
    error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for V
isual Studio": https://visualstudio.microsoft.com/downloads/

this Is the code of my FARADAY AI. I am on python 3.8 (32 bit machine) and python is also of 32 bit.

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

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].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()


       if 'wikipedia' in query:
           speak('Searching wikipedia')
           query = query.replace("wikipedia", "")
           results = wikipedia.summary(query, sentences=2)
           speak("According to Wikipedia")
           print(results)
           speak(results)
       elif  'open Youtube in query':
           webbrowser.open('youtube.com')
       elif 'how handsome am i in query':
           speak('you are very Handsome sir')  
       elif 'open Google in query':
           googlePath = ("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")
           os.startfile(googlePath)         

Solution

  • It is a very common problem, I remember It was my first error on python. You get an error can't install pyaudio because your system don't have the ingredients to build pyaudio. you should go to https://www.lfd.uci.edu/~gohlke/pythonlibs/ and hit Ctrl+F and type pyaudio and download the whl file which matches your machine and python version.

    After you have downloaded It you should Shift + Right click in the directory you have installed It and click on Open power shell window here. and finally type pip install and first letters of the whl file's name and hit TAB and finally Hit ENTER. Boom !

    You have installed pyaudio.