Code Ai Samarth
Code Ai Samarth
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)
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)
else:
talk('Please repeat the instruction.')