Example #1
0
def main():
    global interrupted
    global is_quit

    snowboydecoder.play_audio_file(snowboydecoder.DETECT_DING)
    while True:
        models = ["resources/heyrobo.pmdl", "resources/abort.pmdl"]
        sensitivity = [0.5] * len(models)
        detector = snowboydecoder.HotwordDetector(models,
                                                  sensitivity=sensitivity)
        callbacks = [lambda: quit_detect(), lambda: quit_detect()]

        detector.start(detected_callback=callbacks,
                       interrupt_check=interrupt_callback,
                       sleep_time=0.03)

        #quit if aborted here
        if is_quit:
            snowboydecoder.play_audio_file(snowboydecoder.DETECT_DONG)
            break
        else:
            interrupted = False

        models = [
            "resources/forward.pmdl", "resources/backward.pmdl",
            "resources/left.pmdl", "resources/right.pmdl",
            "resources/stop.pmdl", "resources/abort.pmdl"
        ]

        # capture SIGINT signal, e.g., Ctrl+C
        signal.signal(signal.SIGINT, signal_handler)

        sensitivity = [0.5] * len(models)
        detector = snowboydecoder.HotwordDetector(models,
                                                  sensitivity=sensitivity)
        callbacks = [
            lambda: executeCmd("Forward"), lambda: executeCmd("Backward"),
            lambda: executeCmd("Left"), lambda: executeCmd("Right"),
            lambda: executeCmd("Stop"), lambda: executeCmd("Abort")
        ]

        snowboydecoder.play_audio_file(snowboydecoder.DETECT_DING)
        print('Listening... Press Ctrl+C to exit')

        # main loop
        # make sure you have the same numbers of callbacks and models
        detector.start(detected_callback=callbacks,
                       interrupt_check=interrupt_callback,
                       sleep_time=0.03)
        print("Heyrobo aborted")
        interrupted = False

    detector.terminate()
Example #2
0
    def initialize_detectors(self):
        """
        Returns initialized Catpie HotwordDetector objects
        """
        self.detectors = snowboydecoder.HotwordDetector(
            self.models, self.actions, **self.init_kwargs)

        while not self.detectors.hasAudio:
            self.detectors.terminate()
            time.sleep(5)
            self.detectors = snowboydecoder.HotwordDetector(
                self.models, self.actions, **self.init_kwargs)
Example #3
0
def main():
    detector = snowboydecoder.HotwordDetector(model, sensitivity=0.6)
    recognizer = aiy.cloudspeech.get_recognizer()
    status_ui = aiy.voicehat.get_status_ui()
    aiy.audio.get_recorder().start()

    while True:
        print('INFO:Speak Wake Word and speak')
        status_ui.status('ready')

        global interrupted
        interrupted = False

        detector.start(detected_callback=callbacks,
                       interrupt_check=interrupt_callback,
                       sleep_time=0.03)

        print('INFO:Listening...')
        status_ui.status('thinking')
        text = recognizer.recognize()

        if not text:
            print('INFO:Sorry, I did not hear you.')
        elif text in skills:
            print('INFO:Skill:', text, '"')
            skills[text]()
        else:
            print('INFO:"', text, '"')
            call_assistant(text)
Example #4
0
    def __init__(self, model, assistant, sensitivity=0.5, audio_gain=1.0):
        """
        :param model: Path to the voice model file. See https://snowboy.kitt.ai/ for training/downloading models.
        :type model: str

        :param assistant: Instance of :class:`assistant.Assistant` that will be invoked upon detected hotword.
        :type assistant: assistant.Assistant

        :param sensitivity: Model sensitivity for hotword detection between 0 and 1 (default: 0.5)
        :type sensitivity: float

        :param audio_gain: Audio gain. Default: 1.0
        :type audio_gain: float
        """

        super().__init__()
        self.model_file = os.path.abspath(os.path.expanduser(model))
        self.assistant = assistant
        self.sensitivity = sensitivity
        self.audio_gain = audio_gain
        self.logger = logging.getLogger(__name__)
        self.logger.addHandler(logging.StreamHandler(sys.stdout))

        self.detector = snowboydecoder.HotwordDetector(self.model_file,
                                                       sensitivity=self.sensitivity,
                                                       audio_gain=self.audio_gain)

        self.logger.info('Initialized hotword detection service')
Example #5
0
def main():
    recognizer = sr.Recognizer()
    rgb = Squid(RED_GPIO_LEAD, GREEN_GPIO_LEAD, BLUE_GPIO_LEAD)
    snowboy_detector = snowboydecoder.HotwordDetector(
        SNOWBOY_HOTWORD_LOCATION,
        sensitivity=0.5,
        audio_gain=1
    )

    while True:
        snowboy_detector.listen()
        rgb.set_color(GREEN)

        with sr.Microphone(device_index=2) as source:
            audio = recognizer.listen(source=source, timeout=5, phrase_time_limit=2)
            rgb.set_color(BLUE)

            processor = Processor(audio=audio)

            try:
                processor.run()
            except:
                rgb.set_color(RED)
                sleep(1)

            rgb.set_color(OFF)
Example #6
0
 def start_detection(self, callback_func):
     signal.signal(signal.SIGINT, self.signal_handler)
     self.detector = snowboydecoder.HotwordDetector(self.model,
                                                    sensitivity=0.5)
     self.detector.start(detected_callback=callback_func,
                         interrupt_check=self.interrupt_callback,
                         sleep_time=0.5)
Example #7
0
def main():
    global detector
    global stt
    global config
    global tuling
    global rap
    if len(sys.argv) == 1:
        print("Error: need to specify model name")
        print("Usage: python demo.py your.model")
        sys.exit(-1)

    with open("./config.yaml") as f:
        config = yaml.load(f)

    stt = Baidu(config)
    tuling = Tuling(config)
    rap = rapiro('http://192.168.123.87')
    print(len(sys.argv))
    model = sys.argv[1]

    # capture SIGINT signal, e.g., Ctrl+C
    signal.signal(signal.SIGINT, signal_handler)

    detector = snowboydecoder.HotwordDetector(model, sensitivity=0.5)
    print('Listening... Press Ctrl+C to exit')

    # main loop
    detector.start(detected_callback=detected_callback,
                   interrupt_check=interrupt_callback,
                   sleep_time=0.03)

    detector.terminate()
Example #8
0
    def start(self):
        
        interrupted = False

        def signal_handler(signal, frame):
            global interrupted
            interrupted = True


        def interrupt_callback():
            global interrupted
            return interrupted

        if len(sys.argv) == 1:
            print("Error: need to specify model name")
            print("Usage: python demo.py your.model")
            sys.exit(-1)

        model = self.model

        # capture SIGINT signal, e.g., Ctrl+C
        signal.signal(signal.SIGINT, signal_handler)

        detector = snowboydecoder.HotwordDetector(model, sensitivity=0.5)
        print('Listening... Press Ctrl+C to exit')

        # main loop
        detector.start(detected_callback=snowboydecoder.play_audio_file,
                       interrupt_check=interrupt_callback,
                       sleep_time=0.03)

        detector.terminate()

        return interrupted
        def listening():
            detector = snowboydecoder.HotwordDetector(hotword_model,
                                                      sensitivity=0.38)
            print("Listening... <hotword>, Press Ctrl+C to exit")

            detector.start(detected_callback=detectedCallback, sleep_time=0.01)
            detector.terminate()
Example #10
0
def hotword_detector():
	
	print("Tell the keyword to start conversation")
	
	detector = snowboydecoder.HotwordDetector("resources/saya.pmdl", sensitivity=0.4, audio_gain=1)

	detector.start(detected_callback)
Example #11
0
def main():

    model = sys.argv[1]  # path to hot-word model
    model = 'resources/alexa.umdl'
    mixer.init(frequency=16000)

    # Baidu Voice API, you may need to update your tokens.
    token = BaiduVoice.get_baidu_token('VB5dnaiN1uM3b2tWbUYcOFzE',
                                       '9577cd3eaa69b68040fdfd204fcd19c1')
    bv = BaiduVoice(token['access_token'])

    # Turing Robots Tokens
    chatbot = TuringRobot('2b3e14182a7b4cdaa34d1bb65020f822')

    # ROS topic
    rospy.init_node('chatbot-node')
    pub = rospy.Publisher('/cmd_vel_mux/input/teleop', Twist, queue_size=1)

    # Hot word detector
    signal.signal(signal.SIGINT, signal_handler)
    detector = snowboydecoder.HotwordDetector(model, sensitivity=0.9)
    print('Listening... Press Ctrl+C to exit')

    # main loop
    detector.start(
        detected_callback=lambda: chatbot_callback(bv, chatbot, pub),
        interrupt_check=interrupt_callback,
        sleep_time=0.03)

    detector.terminate()
Example #12
0
    def start(self):
        """Begin listening to spoken commands.

        Note: Control will stay within this object.
        """
        # Grab my callback methods, find the appropriate models, and set up the
        #   sensitivities for each
        callbacks = []
        models = []
        sensitivities = []
        command_mapping = Body.get_commands()
        for command, sensitivity in command_mapping.items():
            callbacks.append(lambda: command(self))
            models.append('models/{}.pmdl'.format(command.__name__))
            sensitivities.append(sensitivity)

        # If I see an interrupt, then I need to stop running
        signal.signal(signal.SIGINT, self.stop)

        detectors = snowboydecoder.HotwordDetector(models,
                                                   sensitivity=sensitivities)

        # Designate me as a running instance
        self.is_running = True

        detectors.start(
            detected_callback=callbacks,
            # If I should no longer be running, then interrupt me
            interrupt_check=lambda: not self.is_running,
            sleep_time=.03)

        detectors.terminate()
Example #13
0
 def __init__(self):
     self.interrupted=False
     self.can_start_conversation=False
     self.assistant=None
     self.sensitivity = [0.5]*len(models)
     self.callbacks = [self.detected]*len(models)
     self.detector = snowboydecoder.HotwordDetector(models, sensitivity=self.sensitivity)
     self.mutestatus=False
     self.interpreter=False
     self.interpconvcounter=0
     self.interpcloudlang1=language
     self.interpttslang1=translanguage
     self.interpcloudlang2=''
     self.interpttslang2=''
     self.singleresposne=False
     self.singledetectedresponse=''
     self.t1 = Thread(target=self.start_detector)
     if GPIOcontrol:
         self.t2 = Thread(target=self.pushbutton)
     if configuration['MQTT']['MQTT_Control']=='Enabled':
         self.t3 = Thread(target=self.mqtt_start)
     if irreceiver!=None:
         self.t4 = Thread(target=self.ircommands)
     if configuration['ADAFRUIT_IO']['ADAFRUIT_IO_CONTROL']=='Enabled':
         self.t5 = Thread(target=self.adafruit_mqtt_start)
Example #14
0
def awaken():

    detector = snowboydecoder.HotwordDetector(
        "/home/pi/xiaolan/xiaolan/snowboy/Alexa.pmdl",
        sensitivity=0.5,
        audio_gain=1)
    detector.start(detected_callback)
Example #15
0
 def start_hotword_detection(self):
     self.detector = snowboydecoder.HotwordDetector(
         ["resources/Alice.pmdl", "resources/stop_the_music.pmdl"],
         sensitivity=[0.45, 0.50],
         audio_gain=3
     )
     self.detector.start([self.detected_callback, self.stop_music_callback])
Example #16
0
def startNLP(model):
    #model = sys.argv[1]
    def detectedCallback():
        detector.terminate()  # So google Assistant can use audio device
        snowboydecoder.play_audio_file(snowboydecoder.DETECT_DING)
        assistant.startAssist()
        snowboydecoder.play_audio_file(snowboydecoder.DETECT_DONG)
        detector.start(detected_callback=detectedCallback,
                       interrupt_check=interrupt_callback,
                       sleep_time=0.03)

    i2c = I2C(SLAVE_ADDR)
    assistant = GoogleAssistant(i2c)

    # capture SIGINT signal, e.g., Ctrl+C
    signal.signal(signal.SIGINT, signal_handler)

    # The obj contains the hotword detection
    snowboydecoder.play_audio_file(snowboydecoder.DETECT_DING)
    snowboydecoder.play_audio_file(snowboydecoder.DETECT_DONG)
    detector = snowboydecoder.HotwordDetector(model, sensitivity=0.5)
    print('Listening... Press Ctrl+C to exit')

    # main loop
    detector.start(
        detected_callback=detectedCallback,  #snowboydecoder.play_audio_file,
        interrupt_check=interrupt_callback,
        sleep_time=0.03)

    detector.terminate()
Example #17
0
def wake_up():

    global detector
    model = 'snowboy.pmdl'  #  唤醒词为 SnowBoy
    # capture SIGINT signal, e.g., Ctrl+C

    signal.signal(signal.SIGINT, signal_handler)

    # 唤醒词检测函数,调整sensitivity参数可修改唤醒词检测的准确性

    detector = snowboydecoder.HotwordDetector(model, sensitivity=0.5)

    print('Listening... please say wake-up word:SnowBoy')
    # main loop
    # 回调函数
    detected_callback = snowboydecoder.play_audio_file
    # 修改回调函数可实现我们想要的功能

    detector.start(
        detected_callback=callbacks,  # 自定义回调函数
        interrupt_check=interrupt_callback,
        sleep_time=0.03)
    # 释放资源

    detector.terminate()
Example #18
0
def start_word_detected():
    print("got the start keyword !")
    # first terminate the start detector
    startDetector.terminate()

    # then start recognizing
    print("now time to start the talk ! ")
    # obtain audio from the microphone
    r = sr.Recognizer()
    m = sr.Microphone()

    while True:
        res = interact_with_device(r, m)
        # if no exception was launched
        if res["error"] is None:
            print(u"You said: {}".format(res["transcription"]))
            processed = process_result(res["transcription"])
            if processed is True or stop_word_detected is True:
                break

    # if we come here : means that interaction is over
    global stop_word_detected
    stop_word_detected = False

    print "back to detecting hotword"
    # start the thread of the detector
    global startDetector
    startDetector = snowboydecoder.HotwordDetector(startModel, sensitivity=0.5)
    startDetector.start(detected_callback=start_word_detected,
                        interrupt_check=interrupt_callback,
                        sleep_time=0.03)
Example #19
0
def snowboy():
    hotword_file = Aion().get_hotword_file()
    logger.info("Set the hotword file", getframeinfo(currentframe()).lineno - 1)

    try:
        global main_pid
        main_pid = os.getpid()
        print("Main PID: " + str(main_pid))
        wake_up = snowboydecoder.HotwordDetector(hotword_file, sensitivity=0.5)
        logger.info("Configured the hotword detector", getframeinfo(currentframe()).lineno - 1)
        logger.info("Starting hotword detection...", getframeinfo(currentframe()).lineno - 1)
        wake_up.start(detected_callback=detected_callback,
                      audio_recorder_callback=main,
                      recording_timeout=50,
                      sleep_time=0.01)

        wake_up.terminate()
    except KeyboardInterrupt:
        variables.close()
        sys.exit(1)
    except Exception:
        print(Fore.CYAN + "Caught error: " + Fore.RED + "\n" + traceback.format_exc() + Fore.RESET)
        error_list = []
        for error in traceback.format_exc().split("\n"):
            error_list.append(error.strip())
        logger.error("Caught error: " + " |-| ".join(error_list), getframeinfo(currentframe()).lineno - 5)
        pass
Example #20
0
def main():
    global ws
    global gloop
    global detector
    global interrupted
    global listening
    interrupted=False
    listening=False

    model = "resources/alexa/alexa_02092017.umdl"
    
    ws = WebsocketClient('ws://localhost:8181/core')
    ws.on('open', handle_open)
    ws.on('recognizer_loop:wakeword', handle_startlisten)
    ws.on('StartListen', handle_startlisten)
    gloop=google_recognizer()
    gloop.on('UtteranceDetected',detected_utterance)
  
    event_thread = Thread(target=mycroft_connect)
    event_thread.setDaemon(True)
    event_thread.start()
    
    signal.signal(signal.SIGINT, signal_handler)
    detector = snowboydecoder.HotwordDetector(model, sensitivity=0.2)
    time.sleep(1)
    print('Listening...')
    detector.start(detected_callback=callback_wakeword,
           interrupt_check=interrupt_callback,
           sleep_time=0.05)

    detector.terminate()
Example #21
0
def detectWake():
    def signal_handler(signal, frame):
        global interrupted
        interrupted = True

    def interrupt_callback():
        global interrupted
        return interrupted

    def callback():
        snowboydecoder.play_audio_file(snowboydecoder.DETECT_DING)
        detector.terminate()
        getUtterance()

    models = setti.models

    # capture SIGINT signal, e.g., Ctrl+C
    signal.signal(signal.SIGINT, signal_handler)

    sensitivity = [0.5] * len(models)
    detector = snowboydecoder.HotwordDetector(models, sensitivity=sensitivity)
    callbacks = [callback] * len(models)

    detector.start(detected_callback=callbacks,
                   interrupt_check=interrupt_callback,
                   sleep_time=0.03)
    def detect_language(self, request = None):
        """
        Detecting a hotword from a model, returning a language code

        Keyword arguments:
        request = ROS Service Message
        """
        # Setting parameters
        languages = ['en-EN', 'de-DE', 'es-ES', 'it-IT', 'nl-NL']
        models = [model_path + "HeyDeNiro.pmdl",
                  model_path + "HalloDeNiro.pmdl",
                  model_path + "HolaDeNiro.pmdl",
                  model_path + "CiaoDeNiro.pmdl",
                  model_path + "HoiDeNiro.pmdl"]

        sensitivity = [0.5]*len(models)

        # Initializing Snowboy (Hotword Detector)
        detector = snowboydecoder.HotwordDetector(models, sensitivity=sensitivity)

        try:
            lang = [None]
            callbacks = [lambda i=i: _return_language(languages[i], lang) for i, val in enumerate(models)]
            detector.start(detected_callback=callbacks, sleep_time=0.03, file=self.file)
        except KeyboardInterrupt: # pragma: no cover
            pass
        detector.terminate()
        print "Returning: " + str(lang[0])
        return lang[0]
    def detect_hotword(self, request = None):
        """
        Detecting a hotword from a model

        Keyword arguments:
        request = ROS Service Message
        """
        # Setting parameters
        models = {
            'en-EN' : model_path + "HeyDeNiro.pmdl",
            'de-DE' : model_path + "HalloDeNiro.pmdl",
            'es-ES' : model_path + "HolaDeNiro.pmdl",
            'it-IT' : model_path + "CiaoDeNiro.pmdl",
            'nl-NL' : model_path + "HoiDeNiro.pmdl"
        }
        sensitivity = [0.5]

        # Initializing Snowboy (Hotword Detector)
        detector = snowboydecoder.HotwordDetector(models[request.lang_in], sensitivity=sensitivity)

        try:
            detector.start(sleep_time=0.03, file=self.file)
        except KeyboardInterrupt: # pragma: no cover
            pass
        detector.terminate()
        print "Returning: " + str(request.lang_in)
        return request.lang_in
Example #24
0
def speechrec_main(listFName):
    models = load_model_list(listFName)
    print 'models = ', models
    time.sleep(1)

    # capture SIGINT signal, e.g., Ctrl+C
    signal.signal(signal.SIGINT, signal_handler)

    sensitivity = [0.5] * len(models)
    detector = snowboydecoder.HotwordDetector(models, sensitivity=sensitivity)
    callbacks = [
        lambda: my_callback(0, models[0]), lambda: my_callback(1, models[1]),
        lambda: my_callback(2, models[2]), lambda: my_callback(3, models[3]),
        lambda: midi_play.Pausepress(), lambda: midi_play.Pausepress(),
        lambda: midi_play.Pausepress(), lambda: midi_play.Pausepress(),
        lambda: midi_play.Fastpress(), lambda: midi_play.Fastpress(),
        lambda: midi_play.Slowpress(), lambda: midi_play.Slowpress(),
        lambda: my_callback(12, models[12]),
        lambda: my_callback(13, models[13]),
        lambda: my_callback(14, models[14]),
        lambda: my_callback(15, models[15]),
        lambda: my_callback(16, models[16]),
        lambda: my_callback(17, models[17]),
        lambda: my_callback(18, models[18]),
        lambda: my_callback(19, models[19])
    ]
    print('Listening... Press Ctrl+C to exit')

    # main loop
    # make sure you have the same numbers of callbacks and models
    detector.start(detected_callback=callbacks,
                   interrupt_check=interrupt_callback,
                   sleep_time=0.5)

    detector.terminate()
Example #25
0
    def __init__(self, models):
        # Flags
        self._detected = False
        self._stop = True

        # capture SIGINT signal, e.g., Ctrl+C
        signal.signal(signal.SIGINT, self.signal_handler)

        # A timer object as well incase we need to detect within a timeout
        self._timeout_timer = None

        # init the detector
        sensitivity = [0.465] * len(models)  # 0.465 is really well-tuned to Angel
        self.detector = \
            snowboydecoder.HotwordDetector(models, sensitivity=sensitivity)
        self.callbacks = [self.notify] * len(models)

        # detection service
        self._srv = rospy.Service('/detect_hotword',
                                  DetectHotWordSrv,
                                  self._srv_callback)

        # hotword detection action
        self._action = actionlib.SimpleActionServer('/detect_hotword',
                                                    DetectHotWordAction,
                                                    self._action_callback,
                                                    auto_start=False)
        self._action.register_preempt_callback(self._action_preempt)
        self._action.start()

        # notify programmmer of init
        rospy.loginfo(rospy.get_name() + ': hotword detector initialized!')
Example #26
0
def startBurton():
  global detector
  detector.terminate()
  burton.runOnce()
  detector = snowboydecoder.HotwordDetector(models, sensitivity=sensitivity)
  detector.start(detected_callback=callbacks,
               interrupt_check=interrupt_callback,
               sleep_time=0.03)
Example #27
0
    def awaken(self):

        detector = snowboydecoder.HotwordDetector(
            "/home/pi/xiaolan/auditory_center/awaken/hotword/jarvis.umdl,/home/pi/xiaolan/auditory_center/awaken/hotword/xiaodu_l12r10_sen_35_35_32_highsen_40_40_39_0104_kuanyang.umdl",
            sensitivity=[0.8, 0.8, 0.4, 0.4, 0.39],
            audio_gain=1,
            apply_frontend=True)
        detector.start(self.a)
Example #28
0
def hotWord(models):
	sensitivity = [0.5]*len(models)
	detector = snowboydecoder.HotwordDetector(models, sensitivity=sensitivity)

	# main loop
	word = detector.start(detected_callback=snowboydecoder.play_audio_file,
					sleep_time=0.03)
	return(word)
Example #29
0
 def __init__(self):
     self.interrupted=False
     self.can_start_conversation=False
     self.assistant=None
     self.sensitivity = [0.5]*len(models)
     self.callbacks = [self.detected]*len(models)
     self.detector = snowboydecoder.HotwordDetector(models, sensitivity=self.sensitivity)
     self.t1 = Thread(target=self.start_detector)
Example #30
0
    def start_listening(self):
        detector = snowboydecoder.HotwordDetector(self.model, sensitivity=0.5)
        print('Listening... Press Ctrl+C to exit')

        detector.start(detected_callback=self.hotword_callback,
                       sleep_time=0.03)

        detector.terminate()