0% found this document useful (0 votes)
6 views1 page

Code Python

The document contains a Python script for a voice assistant that can perform tasks such as searching Wikipedia, opening YouTube, telling the current time, and telling jokes. It uses libraries like speech_recognition for voice input, pyttsx3 for text-to-speech, and webbrowser for opening websites. The assistant runs in a loop until the user says 'exit'.

Uploaded by

vimenik889
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)
6 views1 page

Code Python

The document contains a Python script for a voice assistant that can perform tasks such as searching Wikipedia, opening YouTube, telling the current time, and telling jokes. It uses libraries like speech_recognition for voice input, pyttsx3 for text-to-speech, and webbrowser for opening websites. The assistant runs in a loop until the user says 'exit'.

Uploaded by

vimenik889
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/ 1

import speech_recognition as sr

import pyttsx3
import datetime
import wikipedia
import webbrowser
import pyjokes

def speak(text):
engine = pyttsx3.init()
engine.say(text)
engine.runAndWait()

def take_command():
recognizer = sr.Recognizer()
with sr.Microphone() as source:
audio = recognizer.listen(source)
command = recognizer.recognize_google(audio)
return command.lower()

def run_assistant():
speak("Hello! I am your voice assistant. How can I help you today?")
while True:
query = take_command()
if 'wikipedia' in query:
speak("Searching Wikipedia...")
query = query.replace("wikipedia", "")
result = wikipedia.summary(query, sentences=2)
speak(result)
elif 'open youtube' in query:
webbrowser.open("https://www.youtube.com")
speak("Opening YouTube...")
elif 'time' in query:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak(f"The current time is {strTime}")
elif 'joke' in query:
joke = pyjokes.get_joke()
speak(joke)
elif 'exit' in query:
speak("Goodbye!")
break
else:
speak("Sorry, I didn't understand that.")

run_assistant()

You might also like