0% found this document useful (0 votes)
4 views3 pages

Code Ai Samarth

The document outlines a Python program that creates a voice-activated Google Assistant using libraries such as speech_recognition, pyttsx3, and tkinter. It allows users to perform various tasks like playing music, checking the time and date, and answering questions through voice commands. The assistant also features a graphical user interface (GUI) for user interaction.

Uploaded by

Ashish Kumauni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Code Ai Samarth

The document outlines a Python program that creates a voice-activated Google Assistant using libraries such as speech_recognition, pyttsx3, and tkinter. It allows users to perform various tasks like playing music, checking the time and date, and answering questions through voice commands. The assistant also features a graphical user interface (GUI) for user interaction.

Uploaded by

Ashish Kumauni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import speech_recognition as aa

import pyttsx3
import pywhatkit
import datetime
import wikipedia
import tkinter as tk
import webbrowser

Listener = aa.Recognizer()
machine = pyttsx3.init()

voices = machine.getProperty('voices')
machine.setProperty('voice', voices[1].id)
machine.setProperty('rate', 150)

# Setting up the GUI


root = tk.Tk()
root.title("Google Assistant")
root.geometry("400x300")
output_label = tk.Label(root, text="", wraplength=350, justify="left")
output_label.pack(pady=20)

def update_output(text):
output_label.config(text=text)
root.update()

def talk(text):
machine.say(text)
machine.runAndWait()
update_output(text)

def input_instruction():
global Instruction
try:
with aa.Microphone() as origin:
print("Listening...")
update_output("Listening...")
speech = Listener.listen(origin)
Instruction = Listener.recognize_google(speech)
Instruction = Instruction.lower()
if "google" in Instruction:
Instruction = Instruction.replace('google', '')
print(f"Recognized Instruction: {Instruction}")
except Exception as e:
print(f"Error: {e}")
update_output(f"Error: {e}")
Instruction = ""
return Instruction

def play_Google():
while True:
Instruction = input_instruction()
if not Instruction:
continue

if "play" in Instruction:
song = Instruction.replace('play', "")
talk("Playing " + song)
pywhatkit.playonyt(song)
elif 'time' in Instruction:
time = datetime.datetime.now().strftime('%I:%M %p')
talk('The current time is ' + time)

elif 'date' in Instruction:


date = datetime.datetime.now().strftime('%m/%d/%Y')
talk("Today's date is " + date)

elif 'kaise ho' in Instruction:


talk('Main theek hoon, aap kaise hain?')

elif 'aur bhai kya kar raha hai' in Instruction:


talk('Chutiye dimag kahrab mat kar')

elif 'fix my mood' in Instruction:


talk('Go smoke a joint, it’s Pindari’s stuff today.')

elif 'hey buddy any class today' in Instruction:


talk('today no classes, today movie night')

elif 'hey buddy what is today plan' in Instruction:


talk('yes today you have to go to ramleela')

elif 'what is your name' in Instruction:


talk('I am Google, what can I do for you?')

elif 'what are you doing tomorrow' in Instruction:


talk('I will be home tonight')

elif 'i need your phone number' in Instruction:


talk('likho 8265991334')

elif 'you are amazing' in Instruction:


talk('are you flirting with me')

elif 'i am just appreciating' in Instruction:


talk('thank you')

elif 'can i grab your instagram' in Instruction:


talk('yes sure soniya bijalwan')

elif 'do you listen to uniyal' in Instruction:


talk('yaa vartmaan?')

elif 'wait let me play' in Instruction:


link = "https://www.youtube.com/watch?v=gMC3gEcD3R0"
talk(f"Opening the link: {link}")
webbrowser.open(link)

elif 'who is ' in Instruction:


human = Instruction.replace('who is', "")
try:
info = wikipedia.summary(human, 1)
print(info)
talk(info)
except wikipedia.exceptions.DisambiguationError:
talk('There are multiple results for that name. Please specify
further.')
except wikipedia.exceptions.PageError:
talk("I couldn't find information on that topic.")
except Exception as e:
talk("Sorry, I encountered an error.")

elif "exit" in Instruction or "stop" in Instruction:


talk("Goodbye! Have a great day!")
break

else:
talk('Please repeat the instruction.')

# Start the assistant in the GUI window


tk.Button(root, text="Start Assistant", command=play_Google).pack(pady=10)
root.mainloop()

You might also like