# Demo by Mike Ogrinz. Visit my youtube channel at: https://youtube.com/@ogrinz_labs

import pvporcupine # More info at https://pypi.org/project/pvporcupine/
from pvrecorder import PvRecorder
from gpiozero import LED
from time import sleep

# Get your personal free access key, and create your own .ppn wake word files at:https://console.picovoice.ai/
access_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # AccessKey obtained from Picovoice Console (https://console.picovoice.ai/)
keyword_paths = ['Jarvis_en_raspberry-pi_v3_0_0.ppn']

handle = pvporcupine.create(access_key=access_key, keyword_paths=keyword_paths,sensitivities=[0.6])
# Use this line instead if you want to use one of the built-in wakewords. The available list is:
# ALEXA, AMERICANO,BLUEBERRY, BUMBLEBEE,COMPUTER,GRAPEFRUIT,GRASSHOPPER,HEY_GOOGLE,HEY_SIRI,JARVIS,OK_GOOGLE,PICOVOICE,PORCUPINE,TERMINATOR
#handle = pvporcupine.create(access_key=access_key, keywords=['picovoice'])

recorder = PvRecorder(device_index=3,frame_length=512)
recorder.start()
print ("Listening...")

led = LED(23)

while True:
	keyword_index = handle.process(recorder.read())
	if keyword_index >= 0:
	# detection event logic/callback
		recorder.stop()
		print ("I heard the wake word!")
		led.on()
		sleep(.3)
		led.off()
		recorder.start()
