Пример #1
0
def main():

    model = 'saved_model.pmdl'

    #os.system("espeak 'Hello!' --stdout | aplay")
    global body
    body = robot_body(serial.Serial('/dev/ttyACM0', 9600, timeout=0))
    body.get_feedback()

    device = get_device()
    face = robot_face(device, body)
    eye = robot_eye(None)

    # Set up the ears kitt.ai
    # Initialize ThreadedDetector object and start the detection thread
    threaded_detector = snowboythreaded.ThreadedDetector(model,
                                                         sensitivity=0.5)
    threaded_detector.start()

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

    # main loop
    threaded_detector.start_recog(
        audio_recorder_callback=audioRecorderCallback, sleep_time=0.03)

    # Let audio initialization happen before requesting input
    sleep(1)

    try:
        while True:
            body.distance()
            result = eye.detect_face()
            face.set_gaze(result)
            face.set_dist(body.get_last_distance())

    except KeyboardInterrupt:
        print "Exiting Program"

    except BaseException as e:
        print "Error Occurs, Exiting Program " + str(e)

    finally:
        body.shutdown()
        face.shutdown()
        threaded_detector.terminate()
        pass
Пример #2
0
def pie(state):

    global stop_program
    stop_program = False

    global actions
    actions = Queue.Queue()
    # capture SIGINT signal, e.g., Ctrl+C
    signal.signal(signal.SIGINT, signal_handler)

    # Initialize ThreadedDetector object and start the detection thread
    global threaded_detector
    threaded_detector = snowboythreaded.ThreadedDetector(sensitivity=[])
    threaded_detector.start()

    # main loop
    if state == "eat":
        threaded_detector.start_recog(detected_callback=detectedCallback,
                                      action_callback=actionCallback,
                                      stop_callback=stopCallback,
                                      recording_timeout=8.0,
                                      sleep_time=0.03)
    elif state == "bake":
        threaded_detector.start_recog(detected_callback=detectedCallback,
                                      action_callback=actionCallback,
                                      stop_callback=stopCallback,
                                      sleep_time=0.03,
                                      calibrating=True)
    else:
        stop_program = True

    # Let audio initialization happen before requesting input
    time.sleep(1)

    # Do a simple task separate from the detection - addition of numbers
    while not stop_program:
        action = actions.get()

        if action == "!":
            break

        subprocess.call(action)

    threaded_detector.terminate()
Пример #3
0
    def _process_event(self, event):
        status_ui = aiy.voicehat.get_status_ui()
        if event.type == EventType.ON_START_FINISHED:
            status_ui.status('ready')
            self._can_start_conversation = True
            #Start the voicehat button trigger
            #aiy.voicehat.get_button().on_press(self._on_detect)
            self._snowboy = snowboythreaded.ThreadedDetector(self._on_detect, model, sensitivity=0.5)
            self._snowboy.start()
            self._snowboy.start_recog(sleep_time=0.03)
            if sys.stdout.isatty():
                print('Say "Yogi", then speak. '
                      'Press Ctrl+C to quit...')

        elif event.type == EventType.ON_CONVERSATION_TURN_STARTED:
            self._can_start_conversation = False
            status_ui.status('listening')
            self.msg_queue.put("xl!")

        elif event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED:
            print('You said: ', event.args['text'])
            if event.args['text'].lower() == 'ip address':
                self._assistant.stop_conversation()
                say_ip()

        elif event.type == EventType.ON_END_OF_UTTERANCE:
            status_ui.status('thinking')
            self.msg_queue.put("xt!")

        elif event.type == EventType.ON_RESPONDING_STARTED:
            self.msg_queue.put("xr!")
            self.msg_queue.put("fac 140")

        elif event.type == EventType.ON_RESPONDING_FINISHED:
            self.msg_queue.put("restore")

        elif event.type == EventType.ON_CONVERSATION_TURN_FINISHED:
            status_ui.status('ready')
            self.msg_queue.put("xo!")
            self._can_start_conversation = True

        elif event.type == EventType.ON_ASSISTANT_ERROR and event.args and event.args['is_fatal']:
            sys.exit(1)
Пример #4
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)

    sensitivities = [0.55] * len(models)
    sensitivities[4:8] = [0.45] * 4
    sensitivities[8:10] = [0.6] * 2
    #detector = snowboydecoder.HotwordDetector(models, sensitivity=sensitivity)
    callbacks = [
        lambda: my_callback(0, models[0]),
        lambda: my_callback(1, models[1]),
        lambda: midi_play.Replaypress(),  #2
        lambda: midi_play.Replaypress(),  #3
        lambda: midi_play.Pausepress(),  #4
        lambda: midi_play.Pausepress(),  #5
        lambda: midi_play.Pausepress(),  #6
        lambda: midi_play.Pausepress(),  #7
        lambda: midi_play.Fastpress(),  #8
        lambda: midi_play.Fastpress(),  #9
        lambda: midi_play.Slowpress(),  #10
        lambda: midi_play.Slowpress(),  #11
        lambda: midi_play.Loudpress(),  #12
        lambda: midi_play.Loudpress(),  #13
        lambda: midi_play.Softpress(),  #14
        lambda: midi_play.Softpress(),  #15
        lambda: midi_play.Metropress2(),  #16
        lambda: midi_play.Metropress2(),  #17
        lambda: midi_play.Endpress(),  #18
        lambda: midi_play.Endpress()
    ]  #19
    print('Listening... Press Ctrl+C to exit')
    threaded_detector = snowboythreaded.ThreadedDetector(
        models, callbacks, sensitivity=sensitivities)
    threaded_detector.start()
    threaded_detector.start_recog(sleep_time=0.03)
    time.sleep(1)
    return threaded_detector
Пример #5
0
    global interrupted
    interrupted = True

def interrupt_callback():
    global interrupted
    return interrupted

def detected_callback():
    # vad
    # nlp
    # change cmd global cmd
     print ("hotword detected")

# detector = snowboydecoder.HotwordDetector("/Users/weijiawu/Documents/GitHub/snowboy/resources/models/snowboy.umdl", sensitivity=0.7, audio_gain=1)

threaded_detector = snowboythreaded.ThreadedDetector("/Users/weijiawu/Documents/GitHub/snowboy/resources/models/snowboy.umdl", sensitivity=0.7, audio_gain=1)
# print("Listening... Press Ctrl+C to exit")
# print(detector.detector.SampleRate())
# args =(detectedCallback, interrupt_callback, 0.05, audioRecorderCallback, 15, 50)


threaded_detector.start()

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

# main loop
threaded_detector.start_recog(detected_callback=detectedCallback,
               audio_recorder_callback=audioRecorderCallback,
               # interrupt_check=interrupt_callback,
               sleep_time=0.05,
               recording_timeout=50)
Пример #6
0
isTriggered = False
def triggered():
    global isTriggered
    isTriggered = True

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

wakeup_model = 'resources/thomas.pmdl'

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

# Initialize ThreadedDetector object and start the detection thread
detector = snowboythreaded.ThreadedDetector(wakeup_model, sensitivity=0.8)
detector.start()

detector.start_recog(detected_callback=triggered,sleep_time=0.03)

while 1:
    while(isTriggered):
        pass
    detector.interrupted = True
    isTriggered = False
    utt = asr.get_asr()
    print('asr results: ' + utt)
    response = brain.get_response(utt)
    if response.confidence < SCORE_THRE:
        response = query(utt)
    else:
Пример #7
0

kws = {}
kws['help'] = {'pmdl': "help.pmdl", 'obj': None, 'cb': on_detected_help}

models, cbs = config.loadCfg(kws)

# ========================================

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

ec.prepTTS()

# Initialize ThreadedDetector object and start the detection thread
threaded_detector = snowboythreaded.ThreadedDetector(models, sensitivity=0.5)
threaded_detector.start()

logging.info('Listening... Press Ctrl+C to exit')

# main loop
threaded_detector.start_recog(sleep_time=0.03, detected_callback=cbs)

# Let audio initialization happen before requesting input
time.sleep(1)

# Do a simple task separate from the detection - addition of numbers
while not stop_program:

    try:
        resp = raw_input("<aidex> ")
Пример #8
0
    stop_program = True


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

model = sys.argv[1]

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

# Initialize ThreadedDetector object and start the detection thread
threaded_detector = snowboythreaded.ThreadedDetector(onDetect,
                                                     model,
                                                     sensitivity=0.5)
threaded_detector.start()

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

# main loop
threaded_detector.start_recog(sleep_time=0.03)

# Let audio initialization happen before requesting input
time.sleep(1)

# Do a simple task separate from the detection - addition of numbers
while not stop_program:
    try:
        num1 = int(input("Enter the first number to add: "))