-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_speech.py
More file actions
26 lines (23 loc) · 807 Bytes
/
test_speech.py
File metadata and controls
26 lines (23 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import speech_recognition as sr
r = sr.Recognizer()
print("Testing wake word 'jarvis'...")
while True:
try:
with sr.Microphone() as source:
print("Listening for 'jarvis'...")
audio = r.listen(source, timeout=2, phrase_time_limit=1)
word = r.recognize_google(audio)
print(f"Recognized: {word}")
if word.lower() == "jarvis":
print("Wake word detected!")
break
except sr.WaitTimeoutError:
print("Timeout: No speech detected. Trying again...")
except sr.UnknownValueError:
print("Could not understand audio. Trying again...")
except sr.RequestError as e:
print(f"Request error: {e}")
break
except Exception as e:
print(f"Error: {e}")
break