-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeech.py
More file actions
30 lines (22 loc) · 797 Bytes
/
Copy pathspeech.py
File metadata and controls
30 lines (22 loc) · 797 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
27
28
29
30
import speech_recognition as sr
from events import events
def listen():
recognizer = sr.Recognizer()
with sr.Microphone() as source:
print("🎤 Listening...")
recognizer.adjust_for_ambient_noise(source, duration=1)
audio = recognizer.listen(source)
try:
command = recognizer.recognize_google(audio)
command = command.lower()
print("You :", command) # Fixed trailing line-continuation backslash here
# --- Fixed Indentation Block ---
if events.user_callback:
events.user_callback(command)
return command
except sr.UnknownValueError:
print("Sorry, I didn't understand.")
return ""
except sr.RequestError:
print("Internet connection required.")
return ""