-
Notifications
You must be signed in to change notification settings - Fork 8
/
voice_activated_intention_repeater.py
83 lines (68 loc) · 2.6 KB
/
voice_activated_intention_repeater.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import speech_recognition as sr
import pyttsx3
import subprocess
def speak(text):
engine = pyttsx3.init()
engine.say(text)
engine.runAndWait()
def listen_for_command():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening for command 'run repeater'...")
audio = r.listen(source)
try:
command = r.recognize_google(audio).lower()
print(f"Command: {command}")
return command
except sr.UnknownValueError:
print("Could not understand audio")
except sr.RequestError as e:
print(f"Could not request results from Google Speech Recognition service; {e}")
return ""
def get_intention():
speak("What is your intention?")
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening for intention...")
audio = r.listen(source, phrase_time_limit=2)
try:
intention = r.recognize_google(audio)
print(f"Intention: {intention}")
return intention
except sr.UnknownValueError:
print("Could not understand audio")
except sr.RequestError as e:
print(f"Could not request results from Google Speech Recognition service; {e}")
return ""
def get_yes_no_response(question):
speak(question)
r = sr.Recognizer()
with sr.Microphone() as source:
print(f"Listening for response to: {question}")
audio = r.listen(source, phrase_time_limit=2)
try:
response = r.recognize_google(audio).lower()
print(f"Response: {response}")
return "yes" in response
except sr.UnknownValueError:
print("Could not understand audio")
except sr.RequestError as e:
print(f"Could not request results from Google Speech Recognition service; {e}")
return False
def main():
while True:
command = listen_for_command()
if "run repeater intention" in command:
intention = command.split("run repeater intention", 1)[1].strip()
if not intention:
intention = get_intention()
elif "run repeater" in command:
intention = get_intention()
else:
continue
compress = "y" if get_yes_no_response("Would you like compression?") else "n"
hashing = "y" if get_yes_no_response("Would you like hashing?") else "n"
speak("Launching intention repeater")
subprocess.run(["intention_repeater_max.exe", "--intent", intention, "--compress", compress, "--hashing", hashing, "--dur", "00:10:00"])
if __name__ == "__main__":
main()