0% found this document useful (0 votes)
35 views2 pages

Assistant

Uploaded by

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

Assistant

Uploaded by

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

import speech_recognition as sr

import pyttsx3

import webbrowser

import os

# Initialize the speech recognizer and engine

recognizer = sr.Recognizer()

engine = pyttsx3.init()

def listen():

with sr.Microphone() as source:

print("Listening...")

audio = recognizer.listen(source)

try:

text = recognizer.recognize_google(audio)

print("You said:", text)

return text

except sr.UnknownValueError:

print("Sorry, I didn't understand that.")

except sr.RequestError:

print("Sorry, there was an error processing your request.")

return ""

def speak(text):

engine.say(text)

engine.runAndWait()
def process_command(command):

if "hello" in command:

speak("Hello! How can I assist you?")

elif "open Google" in command:

speak("Opening Google.")

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

elif "play music" in command:

speak("Playing music.")

# Add your code to play music here (e.g., using a media player library)

elif "goodbye" in command:

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

exit()

else:

speak("Sorry, I can't help with that.")

# Main loop

while True:

command = listen().lower()

process_command(command)

You might also like