import speech_recognition as sr
import pyttsx3
import datetime
import wikipedia
import webbrowser
import time
Initialize text-to-speech engine
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
def speak(text):
engine.say(text)
engine.runAndWait()
def wish_me():
hour = datetime.datetime.now().hour
if hour >= 0 and hour < 12:
speak("Karabo, Good Morning!")
elif hour >= 12 and hour < 18:
speak("Karabo, Good Afternoon!")
else:
speak("Karabo, Good Evening!")
def take_command():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
audio = r.listen(source)
try:
statement = r.recognize_google(audio, language="en-in")
print(f"User said: {statement}\n")
return statement
except sr.UnknownValueError:
speak("Karabo, I didn't hear you. Please say that again.")
return "none"
except sr.RequestError:
speak("Karabo, there seems to be an issue with the speech recognition service.")
return "none"
if name == "main":
speak("Loading Gee")
wish_me()
while True:
speak("Wassup bro, what can I do for you?")
statement = take_command().lower()
if statement == "none":
continue
if "goodbye" in statement or "ok bye" in statement or "turn off" in statement:
speak("I gotta bounce, see you later!")
break
if "wikipedia" in statement:
speak("Search