Kitt-AI / snowboy

Future versions with model training module will be maintained through a forked version here: https://github.com/seasalt-ai/snowboy
Other
3.07k stars 996 forks source link

Continue to listen to another hotword after hotword detection #352

Open paulmunns opened 6 years ago

paulmunns commented 6 years ago

So it kinda hard to explain it in 1 sentence but the following thing is what i want to implement. So when you say a hotword, snowboy will detect it and run a script. In this script i will move a motor for a few seconds. While he is executing the script, i want him to continue to listen for another hotword and interrupt the script he was busy with. An example is that i say stop and the motor stops ofcourse. So i was searching for multiprocessing to do this but im kinda new in Python and would like to know if its possible to do what i have in mind.

Any help is welcome.

chenguoguo commented 6 years ago

It's definitely possible, you can run Snowboy in one thread, and run other stuff in another thread.

paulmunns commented 6 years ago

So i have finally figured it out and its working! But now i have 1 little problem. Im also trying to make the rotation of the motor slower, by the hotword slower.

  1. Hotword MoveUp detected, running script that moves the motor for 1 minute.
  2. right after that i call the hotword Slower, it lowers the duty cycle of the PWM signal.

But the problem is that the motor is not going slower. I have one global variable named D (duty cycle).

When i recall the function MoveUp, only then the new duty cycle is applied and the motor goes slower.

import RPi.GPIO as GPIO import time

globale variable

D = 50 #dutycycle

def Moveup(pin): global D GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(pin,GPIO.OUT) print("Up") p = GPIO.PWM(pin,100) p.start(0) p.ChangeDutyCycle(D) time.sleep(60) print("Stop")

def Slower(): global D if 0 < D <= 100: D -= 25 print("Slower") else: print("Minimum speed acquired")