-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpicovoice_demo.py
More file actions
42 lines (34 loc) · 912 Bytes
/
Copy pathpicovoice_demo.py
File metadata and controls
42 lines (34 loc) · 912 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
41
42
import pvporcupine
import dotenv
import os
import pyaudio
import numpy as np
dotenv.load_dotenv()
pico_key = os.getenv("PICO_ACCES_KEY")
porcupine = pvporcupine.create(
access_key=pico_key,
keyword_paths=['picovoice_models/yo-skull_en_mac_v3_0_0.ppn']
)
pa = pyaudio.PyAudio()
audio_stream = pa.open(
rate=16000,
channels=1,
format=pyaudio.paInt16,
input=True,
frames_per_buffer=porcupine.frame_length,
input_device_index=None
)
try:
while True:
pcm = audio_stream.read(porcupine.frame_length)
pcm = np.frombuffer(pcm, dtype=np.int16)
keyword_index = porcupine.process(pcm)
if keyword_index == 0:
print("detected 'yo skull'")
elif keyword_index == 1:
print('detected `bumblebee`')
finally:
audio_stream.stop_stream()
audio_stream.close()
pa.terminate()
porcupine.delete()