-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.py
More file actions
73 lines (57 loc) · 2 KB
/
Copy pathclient.py
File metadata and controls
73 lines (57 loc) · 2 KB
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
import sys
import asyncio
import websockets
import json
async def main():
uri = "ws://localhost:5600/api/hotword/listen"
async with websockets.connect(uri) as websocket:
# example for Vosk (not very accurate)
hotword_params = {
"dev_index": None,
"hotwords": ["hey jarvis", "hey agent"],
"model_engine_hotword": "vosk",
"model_name_hotword": "vosk-model-en-us-0.22",
"model_engine_stt": "openai_whisper",
"model_name_stt": "small.en",
"target_latency": 100,
"silence_duration": 2
}
# example for Pvporcupine (commercial)
hotword_params = {
"dev_index": None,
"hotwords": ["hey agent", "bumblebee"],
"model_engine_hotword": "pvporcupine",
"model_name_hotword": None,
"model_engine_stt": "openai_whisper",
"model_name_stt": "small.en",
"target_latency": 100,
"silence_duration": 2
}
# example for Openwakeword (accurate and free)
hotword_params = {
"dev_index": None,
"hotwords": ["hey_jarvis"],
"model_engine_hotword": "openwakeword",
"model_name_hotword": None,
"model_engine_stt": "openai_whisper",
"model_name_stt": "small.en",
"target_latency": 80,
"silence_duration": 2
}
print("Setting up hotword detection. Please wait...", flush=True)
await websocket.send(json.dumps(hotword_params))
while True:
try:
msg = await websocket.recv()
print(f"\nSERVER: {msg}", flush=True)
except websockets.exceptions.ConnectionClosed:
print("Connection closed by server.", flush=True)
break
def run():
try:
asyncio.run(main())
except KeyboardInterrupt:
print("\nForced shutdown.")
sys.exit(1)
if __name__ == "__main__":
run()