-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathactivate.py
31 lines (25 loc) · 1.08 KB
/
activate.py
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
31
import speech_recognition as sr
# Function that will be called upon saying "activate"
def target_function():
print("Activation successful! Target function is called.")
# Function that listens for the "activate" command
def listen_for_activation():
recognizer = sr.Recognizer()
with sr.Microphone() as source:
print("Listening for the command...")
audio = recognizer.listen(source)
try:
# Recognize speech using Google Web Speech API
command = recognizer.recognize_google(audio).lower()
print(f"Command received: {command}")
# Check if the command is "activate"
if "activate" in command:
target_function()
else:
print("Command not recognized. Say 'activate' to trigger the function.")
except sr.UnknownValueError:
print("Sorry, could not understand the audio.")
except sr.RequestError:
print("Could not request results; check your network connection.")
# Usage
listen_for_activation()