my 1 st ai (code hai python me a)

 import pyttsx3

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



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,Master have a nice day")
       
    elif hour >= 12 and hour <18:
        speak("Good Afternoon, Master")
       
    else:
        speak("Good Evening!, Master")
               
    speak("I am Ghost .AI, Please tell me how may I help you")
       
def takeCommand():
    #it takes microphone input from the user and return string output
   
    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-in')
        print(f"User said:  {query}\n")
   
    except Exception as e :
        # print(e)
        print("Say the again please...")
        return "None"
    return query

if __name__ == "__main__":
   WishME()
#    while True:  
# for continue loop

if 1:
     query = takeCommand().lower()  #logic for 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)
        print(results)
       
     elif 'open youtube' in query:
         webbrowser.open("https://www.youtube.com/")
         
     elif 'open google' in query:
         webbrowser.open("https://www.google.com/")
     elif 'open my website' in query:
         webbrowser.open("https://paradox-avi.blogspot.com")
         
         
     elif 'open my studio' in query:
         webbrowser.open("https://teespring.com/design-launcher?_gl=1*1v3ad78*_ga*NTYxMjQ4MTYzLjE2OTU4OTUyMTI.*_ga_PKGJ770MJQ*MTY5NTg5NTIxMy4xLjEuMTY5NTg5OTA1NS4wLjAuMA..*_ga_G3GKJFR6Z9*MTY5NTg5NTIxMy4xLjEuMTY5NTg5OTA1Ny4wLjAuMA..")
         
     elif 'open my blogger' in query:
         webbrowser.open("https://draft.blogger.com/blog/posts/2063309725377987162?hl=en")
     

     elif 'play music' in query:
       music_dir = 'E:\\COMEDY NIGHTS vdos\\audio\\ipod'
       songs = os.listdir(music_dir)
       print(songs)
       random_song = random.choice(songs)
       os.startfile(os.path.join(music_dir, random_song))

     elif 'the time' in query:
        strTime = datetime.datetime.now().strftime("%H:%M:%S")
        speak(f"Sir, the time is {strTime}")
       
       
     elif 'open vs code' in query:
        codePath = "C:\\Users\\user\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
        os.startfile(codePath)
       
     elif 'open chrome' in query:
        codePath = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
        os.startfile(codePath)
       
       

AVI.PARADOX..

Welcome to my blog! My name is PARADOX, and I’m thrilled to have you here., From the first “Hello, World!”.As a passionate coder, I find joy in the logic and structure of coding., This blog is more than just a collection of articles. It’s a community for those who love to gain knowledge as much as I do., So whether you’re here to learn something new, share your own knowledge, or just to be part of the community, I’m glad you’re here.

Post a Comment

Previous Post Next Post

Contact Form