• Building Jarvis: A Python Voice Assistant for Everyday Tasks

    Introduction

    Voice assistants have revolutionized the way we interact with technology. From setting reminders to fetching news, these AI-powered assistants make automation seamless. In this article, I will walk you through the development of Jarvis, a Python-based voice assistant capable of performing various tasks such as opening websites, playing music, and fetching live news updates.

    Features of Jarvis

    Jarvis is designed to:

    • Open commonly used websites such as Google, Facebook, YouTube, and LinkedIn.
    • Play music based on voice commands.
    • Fetch the latest news updates using an API.
    • Recognize voice input and execute commands accordingly.

    Tech Stack Used

    The core technologies and libraries used to develop Jarvis include:

    • Python: The primary programming language.
    • pyttsx3: A text-to-speech conversion library.
    • SpeechRecognition: For capturing and recognizing voice commands.
    • Webbrowser: To open websites upon request.
    • Requests: To fetch live news updates from an API.
    • Custom Music Library: To play requested songs.

    Full Source Code

    Below is the complete Python script for Jarvis, including all its functionalities:

    import pyttsx3
    import speech_recognition as sr
    import webbrowser
    import musiclibrary
    import requests
    
    news_api = "YOUR_NEWS_API_KEY"
    choice = True
    Recognizer = sr.Recognizer()
    Engine = pyttsx3.init()
    Engine.setProperty('rate', 150)
    
    def Speak(Text):
        Engine.say(Text)
        Engine.runAndWait()
    
    def ProcessCommand(command):
        if "open google" in command.lower():
            webbrowser.open("https://google.com")
        elif "open facebook" in command.lower():
            webbrowser.open("https://facebook.com")
        elif "open youtube" in command.lower():
            webbrowser.open("https://youtube.com")
        elif "open linkedin" in command.lower():
            webbrowser.open("https://linkedin.com")
        elif "open instagram" in command.lower():
            webbrowser.open("https://instagram.com")
        elif "open monkeytype" in command.lower():
            webbrowser.open("https://monkeytype.com")
        elif "open wikipedia" in command.lower():
            webbrowser.open("https://wikipedia.org")
        elif command.lower().startswith("play"):
            song = command.lower().split(" ")[1]
            link = musiclibrary.music[song]
            Speak("Playing your song")
            webbrowser.open(link)
        elif "bulletin" or "bullet" in command.lower():
            r = requests.get(f"https://api.thenewsapi.com/v1/news/all?api_token={news_api}&language=en&limit=3")
            if r.status_code == 200:
                Data = r.json()
                Articles = Data.get('data', [])
                for Article in Articles[:5]:
                    title = Article.get("title", "No title available")
                    Speak(f"News update: {title}")
                    print(f"News update: {title}")
            else:
                Speak("Sorry, I couldn't fetch the news right now.")
        else:
            webbrowser.open(command)
    
    if __name__ == "__main__":
        Speak("Initializing Jarvis...")
        while choice:
            r = sr.Recognizer()
            try:
                with sr.Microphone() as Source:
                    print("Listening...")
                    Audio = r.listen(Source, timeout=2, phrase_time_limit=2)
                    print("Recognizing...")
                    Command = r.recognize_google(Audio)
                    print(Command)
                if Command.lower() == "jarvis":
                    print("Yeah...")
                    Speak("Yeah")
                    with sr.Microphone() as source:
                        Audio = r.listen(source)
                        Command = r.recognize_google(Audio)
                        ProcessCommand(Command)
            except sr.UnknownValueError:
                print("Unable to listen please try again...")
            except Exception as e:
                print(f"Error: {e}")
    

    Challenges Faced & Future Improvements

    • Speech Recognition Accuracy: Background noise can sometimes affect recognition accuracy. Adding noise reduction techniques can help.
    • Adding More Functionalities: Features like setting reminders, sending emails, and home automation can be integrated.
    • Better Music Integration: Instead of fetching from a predefined list, using APIs like Spotify's would enhance the user experience.

    Conclusion

    Developing a voice-activated AI assistant like Jarvis is an exciting way to explore AI, automation, and Python libraries. This project can be expanded with more intelligent features, making it a useful personal assistant.

    Have any suggestions or improvements? Let me know your thoughts!

  • 0 Comments:

    Post a Comment

    GET A FREE QUOTE NOW

    Have questions about fees or need personalized assistance? Feel free to visit my LinkedIn profile for more details and inquiries!

    Powered by Blogger.
    ADDRESS

    CB-1279, Street no 8, Chour Chowk, Rawalpindi, Pakistan

    EMAIL

    adnanxn34101@gmail.com

    MOBILE PHONE

    +92346-802913-8
    +92317-052974-0