15 from threading
import Thread
18 from pvrecorder
import PvRecorder
21 'alexa',
'americano',
'blueberry',
'bumblebee',
'computer',
'grapefruit',
'grasshopper',
'hey google',
'hey siri',
22 'jarvis',
'picovoice',
'porcupine'
27 def __init__(self, access_key, device_index, keyword_var):
43 ppn = pvporcupine.create(access_key=self.
_access_key, keywords=KEYWORDS, sensitivities=[0.75] * len(KEYWORDS))
45 recorder = PvRecorder(device_index=self.
_device_index, frame_length=ppn.frame_length)
52 keyword_index = ppn.process(pcm)
53 if keyword_index >= 0:
57 if recorder
is not None:
76 parser = argparse.ArgumentParser()
78 parser.add_argument(
'--access_key',
79 help=
'AccessKey obtained from Picovoice Console (https://picovoice.ai/console/)',
82 parser.add_argument(
'--audio_device_index', help=
'Index of input audio device.', type=int, default=-1)
84 args = parser.parse_args()
87 window.title(
'Porcupine Demo')
88 window.minsize(width=300, height=400)
90 keyword_var = tk.StringVar(window)
93 tk.Radiobutton(window, text=x, variable=keyword_var, value=x, indicator=0).pack(fill=tk.X, ipady=5)
96 device_index=args.audio_device_index,
97 keyword_var=keyword_var)
100 porcupine_thread.stop()
101 while not porcupine_thread.is_stopped():
105 window.protocol(
'WM_DELETE_WINDOW', on_close)
107 porcupine_thread.start()
108 while not porcupine_thread.is_ready():
114 if __name__ ==
'__main__':