-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (30 loc) · 890 Bytes
/
main.py
File metadata and controls
40 lines (30 loc) · 890 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
31
32
33
34
35
36
37
38
39
40
import pvporcupine
from dotenv import load_dotenv
import os
from pvrecorder import PvRecorder
load_dotenv()
API_KEY = os.getenv("PV_API_KEY")
if not API_KEY:
raise ValueError("PV_API_KEY not found in environment variables!")
KEYWORDS = list(pvporcupine.KEYWORDS)
print(KEYWORDS)
porcupine = pvporcupine.create(
access_key=API_KEY,
keywords=KEYWORDS,
sensitivities=[0.8]* len(KEYWORDS)
)
recorder = PvRecorder(frame_length=porcupine.frame_length, device_index=-1)
print("Listening for wake words... (Ctrl+C to stop)")
try:
recorder.start()
while True:
frame = recorder.read()
keyword_index = porcupine.process(frame)
if keyword_index >= 0:
print(f"Wake word detected: {KEYWORDS[keyword_index]}")
except KeyboardInterrupt:
print("Stopping...")
finally:
recorder.stop()
recorder.delete()
porcupine.delete()