-
Notifications
You must be signed in to change notification settings - Fork 695
Open
Description
import speech_recognition as sr
import pyttsx3
import wikipedia
recognizer = sr.Recognizer()
recognizer.energy_threshold = 300
recognizer.dynamic_energy_threshold = False
engine = pyttsx3.init("sapi5")
engine.setProperty("rate", 190)
def speak(text):
engine.say(text)
engine.runAndWait()
print("Say 'laptop' to activate...")
while True:
try:
# Wake word
with sr.Microphone() as source:
audio = recognizer.listen(source, timeout=1, phrase_time_limit=1)
word = recognizer.recognize_google(audio).lower()
if word == "laptop":
speak("ya")
# Question
with sr.Microphone() as source:
print("Ask your question...")
audio = recognizer.listen(source, timeout=3, phrase_time_limit=5)
question = recognizer.recognize_google(audio)
print("Question:", question)
# Wikipedia answer
try:
answer = wikipedia.summary(question, sentences=2)
print("Answer:", answer)
speak(answer)
except wikipedia.exceptions.DisambiguationError:
speak("Your question is unclear. Please be more specific.")
except wikipedia.exceptions.PageError:
speak("I could not find an answer.")
except sr.UnknownValueError:
pass
except sr.WaitTimeoutError:
pass
except Exception as e:
print("Error:", e)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels