JARVIS AI

                                                           AI TOOL

AI tool  first greet Good morning, Good evening, Good Night

Jarvis ai tool ask any thing ex.  virat kohli in wikipedia hear answer

you speak play music.   hear music

AI tool  first greet Good morning, Good evening, Good Night

import speech_recognition as sr

import pyttsx3

import datetime

import webbrowser

import os

import smtplib

import requests

import json

import random


def speak(text):

    engine = pyttsx3.init()

    engine.say(text)

    engine.runAndWait()


def listen():

    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-us')

        print(f"User said: {query}\n")

    except Exception as e:

        print("Sorry, I couldn't understand that. Can you please repeat?")

        return "None"

    return query


def send_email(receiver_email, subject, body):

    # You need to enable less secure apps in your Google account settings

    # Or use app passwords if 2-factor authentication is enabled

    sender_email = "your_email@gmail.com"

    password = "your_password"


    server = smtplib.SMTP('smtp.gmail.com', 587)

    server.starttls()

    server.login(sender_email, password)

    server.sendmail(sender_email, receiver_email, f"Subject: {subject}\n\n{body}")

    server.quit()


def get_weather(city):

    api_key = "your_api_key"

    url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"

    response = requests.get(url)

    data = response.json()

    if data["cod"] == 200:

        weather_info = data["weather"][0]["description"]

        temp = data["main"]["temp"]

        return f"The weather in {city} is {weather_info} with a temperature of {temp} degrees Celsius."

    else:

        return "Sorry, I couldn't fetch the weather information right now."


def assistant():

    speak("Hello! I'm your Python voice assistant. How can I assist you today?")

    while True:

        query = listen().lower()

        if "hello" in query:

            speak("Hi there! How can I help?")

        elif "how are you" in query:

            speak("I'm just a computer program, so I don't have feelings, but I'm here to assist you!")

        elif "thank you" in query:

            speak("You're welcome! Feel free to ask if you need anything else.")

        elif "what time is it" in query:

            time = datetime.datetime.now().strftime("%H:%M")

            speak(f"It's {time} right now.")

        elif "open google" in query:

            webbrowser.open("https://www.google.com")

        elif "search for" in query:

            search_query = query.replace("search for", "").strip()

            webbrowser.open(f"https://www.google.com/search?q={search_query}")

        elif "send email" in query:

            try:

                speak("What should I say in the email?")

                email_body = listen()

                speak("Who is the receiver?")

                receiver_email = input("Receiver's Email: ")

                send_email(receiver_email, "Subject", email_body)

                speak("Email has been sent successfully!")

            except Exception as e:

                print(e)

                speak("Sorry, I couldn't send the email. Please try again.")

        elif "weather in" in query:

            city = query.split("weather in")[1].strip()

            weather_info = get_weather(city)

            speak(weather_info)

        elif "exit" in query or "bye" in query:

            speak("Goodbye! Have a great day!")

            break

        else:

            speak("I'm sorry, I didn't understand that. Can you please repeat or ask something else?")

    '''def play_music():

    # Path to your music directory

    music_dir = "Music"

    songs = os.listdir(music_dir)

    song = random.choice(songs)

    os.startfile(os.path.join(music_dir, song))'''


if __name__ == "__main__":

    assistant()

 

Comments

Popular posts from this blog

ADD TWO NO. IN JAVA USING APPLET

TO-DO LIST USING HTML CSS JS