forked from unconv/ok-gpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecognize.py
36 lines (28 loc) · 909 Bytes
/
recognize.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
import json
import sys
import os
import playsound
from pathlib import Path
from recorder import live_speech
playsound.playsound(Path(__file__).parent / "sounds" / "bootup.mp3")
def detect_wakeup(command: str, wakeup_words: list[str]):
command = command.lower()
for word in wakeup_words:
word = word.lower()
if word in command:
return True
return False
if not os.path.exists("wakeup_words.json"):
print("You must run init.py first!")
sys.exit(1)
with open("wakeup_words.json", "r") as f:
wakeup_words = json.load(f)
while True:
for message in live_speech():
if detect_wakeup(message, wakeup_words):
print(f"Detected: {message}")
playsound.playsound(Path(__file__).parent / "sounds" / "detected.mp3")
break
for message in live_speech(50):
print (f"Command: {message}")
break