示例#1
0
 def on_handler_started(self, message):
     """When a skill begins executing turn on the LED ring"""
     handler = message.data.get('handler', '')
     if self._skip_handler(handler):
         return
     pixel_ring.set_color_palette(self.main_blue, self.tertiary_green)
     pixel_ring.think()
示例#2
0
def task(quit_event):
    #mic = Microphone(quit_event=quit_event)
    mic_index = None
    for i, microphone_name in enumerate(Microphone.list_microphone_names()):
        if 'seeed' in microphone_name:
            mic_index = i
            print("Using microphone {}".format(microphone_name))
            break
    if not mic_index:
        print("Could not find a proper microphone")
        exit()
    with Microphone(device_index=mic_index) as mic:
        recognizer = Recognizer()
        while not quit_event.is_set():
            pixel_ring.off()
            print("Listening for keyword")
            data = recognizer.listen(source=mic)
            kw_text = recognizer.recognize_sphinx(data)
            print("Heard '{}' while listening for keyword".format(kw_text))
            if kw_text == name:
                print('Wake up')
                pixel_ring.listen()
                data = recognizer.listen(mic)
                pixel_ring.think()
                text = recognizer.recognize_sphinx(data)
                print('Done listening')
                pixel_ring.off()
                if text:
                    print('Recognized {}'.format(text))
                    tts.say(text)
示例#3
0
def process_event(event):
    """Pretty prints events.

    Prints all events that occur with two spaces between each new
    conversation and a single space between turns of a conversation.

    Args:
        event(event.Event): The current event to process.
    """
    print("event:" + str(event))

    if event.type == EventType.ON_CONVERSATION_TURN_STARTED:
        subprocess.Popen(
            ["aplay", "/home/pi/piassistant/src/sample-audio/Fb.wav"],
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        pixel_ring.listen()

    if event.type == EventType.ON_RESPONDING_STARTED:
        pixel_ring.speak()

    if event.type == EventType.ON_RESPONDING_FINISHED or event.type == EventType.ON_CONVERSATION_TURN_TIMEOUT or event.type == EventType.ON_NO_RESPONSE:
        pixel_ring.off()

    if event.type == EventType.ON_END_OF_UTTERANCE:
        pixel_ring.think()

    if (event.type == EventType.ON_CONVERSATION_TURN_FINISHED and event.args
            and not event.args['with_follow_on_turn']):
        pixel_ring.off()

    if event.type == EventType.ON_DEVICE_ACTION:
        for command, params in event.actions:
            print('Do command', command, 'with params', str(params))
示例#4
0
def turn_onoff(onoff):
    pixel_ring.off()
    pixel_ring.think()
    print("Turned " + onoff)
    requests.post("https://maker.ifttt.com/trigger/turn_" + onoff + "_bedroom_light_request/with/key/"+iftttkey)
    requests.post("https://maker.ifttt.com/trigger/turn_" + onoff + "_bedside_light/with/key/"+iftttkey)

    pixel_ring.off()
示例#5
0
def on_message(client, userdata, message):
    if message.topic == "hermes/hotword/default/detected":
        pixel_ring.wakeup()
    if message.topic == "hermes/asr/textCaptured":
        pixel_ring.think()
        time.sleep(3)
        pixel_ring.off()
    #print("message received " ,str(message.payload.decode("utf-8")))
    print("message topic=", message.topic)
示例#6
0
def parse_command_module(word_list):
    pixel_ring.think()
    print("parsing command module from: "+ str(word_list))
    if (set(word_list) & set(LIGHT_WORDS)):
        parse_light_command(word_list)
    else:
        pixel_ring.off()
        time.sleep(1)
        power.off()
        print("no light command found, so i stop because i am simple")
示例#7
0
 def record_begin_handler(self, message):
     pixel_ring.wakeup()
     time.sleep(2)
     pixel_ring.think()
     time.sleep(2)
     pixel_ring.speak()
     time.sleep(3)
     pixel_ring.off()
     time.sleep(2)
     pixel_ring.off()
示例#8
0
    def record_begin_handler(self, message):
        en = mraa.Gpio(12)
        if os.geteuid() != 0:
            time.sleep(1)

        en.dir(mraa.DIR_OUT)
        en.write(0)

        pixel_ring.set_brightness(20)
        pixel_ring.think()
        print('I\'m awake')
def on_message(client, userdata, msg):
    if msg.topic.find("audioServer") != -1:
        return
    print msg.topic
    if msg.topic.find("hermes/hotword/default/detected") != -1:
        pixel_ring.wakeup()
        return
    if msg.topic.find("hermes/dialogueManager/sessionStarted") != -1:
        pixel_ring.think()
        return
    if msg.topic.find("hermes/dialogueManager/sessionEnded") != -1:
        pixel_ring.off()
        return
示例#10
0
 def _proc_audio(self, recog, audio):
     txt = recog.recognize_sphinx(audio)
     if txt == self.name:
         try:
             self.stop()
             tts.say(get_greeting())
             pixel_ring.listen()
             cmd_aud = recog.listen(self.mic, timeout=10)
         except speech_recognition.WaitTimeoutError:
             pixel_ring.off()
             return
         pixel_ring.think()
         cmd_txt = recog.recognize_sphinx(cmd_aud)
示例#11
0
文件: simon.py 项目: smokes2345/simon
def task(quit_event):
    with Microphone(device_index=mic_index, quit_event=quit_event) as mic:
        recognizer = Recognizer()
        while not quit_event.is_set():
            pixel_ring.off()
            print("Listening for keyword")
            data = recognizer.listen(source=mic)
            kw_text = recognizer.recognize_sphinx(data)
            print("Heard '{}' while listening for keyword".format(kw_text))
            if kw_text == name:
                print('Wake up')
                pixel_ring.listen()
                data = recognizer.listen(mic)
                pixel_ring.think()
                text = recognizer.recognize_sphinx(data)
                print('Done listening')
                pixel_ring.off()
                if text:
                    print('Recognized {}'.format(text))
                    tts.say(text)
示例#12
0
 def on_message(client, userdata, msg):
     LOGGER.debug(
         "Received '%s' from '%s' topic",
         msg.payload.decode(), msg.topic
         )
     if "sessionStarted" in msg.topic:
         # listening
         LOGGER.debug("Light waking up")
         pixel_ring.wakeup()
     elif "stopListening" in msg.topic:
         # processing
         LOGGER.debug("Light processing...")
         pixel_ring.think()
     elif "intentParsed" in msg.topic:
         # command detected
         LOGGER.debug("Light speaking...")
         pixel_ring.speak()
     elif "sessionEnded" in msg.topic:
         # stop flashing
         LOGGER.debug("Light turning off...")
         pixel_ring.off()
示例#13
0
文件: simon.py 项目: smokes2345/simon
 def _proc_audio(self, recog, audio):
     try:
         # decoded = recog.recognize_sphinx(audio, show_all=True)
         # txt = decoded.hyp().hypstr
         txt = recog.recognize_google(audio, show_all=True)
         print(f"recognized utterance: {txt}")
     except UnknownValueError as e:
         # txt = recog.recognize_google(audio)
         print("Did not recognize utterance")
         # print(txt)
     if self.name in txt:
         self.wake_up()
     if self.awake and not txt.endswith(self.name):
         print(f"Sending commands: {txt}")
         pixel_ring.think()
         # send command to HA here
         pixel_ring.off()
         self.awake = False
     else:
         print(f"Not awake or name was give without command")
     return
示例#14
0
def on_message(client, userdata, msg):
    payload = json.loads(msg.payload)
    logger.debug("Topic:{0}, Payload:{1}".format(msg.topic, payload))
    if msg.topic == 'hermes/hotword/default/detected':
        logger.info("Hotword detected!")
        pixel_ring.think()  # actually listening
    elif msg.topic == 'hermes/asr/textCaptured':
        logger.info("Command captured! [{0}]".format(msg.topic))
        pixel_ring.set_color(r=200)
        time.sleep(0.5)
        pixel_ring.off()
    elif msg.topic == 'hermes/intent/taka-wang:AutoRun':
        logger.info("Intent topic: [{0}]".format(msg.topic))
        pixel_ring.set_color(r=204, g=46, b=250)
        time.sleep(1)
        pixel_ring.off()
    elif msg.topic == 'hermes/intent/taka-wang:Stop':
        logger.info("Intent topic: [{0}]".format(msg.topic))
        pixel_ring.set_color(g=100)
        time.sleep(1)
        pixel_ring.off()
    elif msg.topic == 'hermes/intent/taka-wang:OpenTheDoor':
        logger.info("Intent topic: [{0}]".format(msg.topic))
        pixel_ring.set_color(g=255)
        time.sleep(1)
        pixel_ring.off()
    elif msg.topic == 'hermes/intent/taka-wang:CloseTheDoor':
        logger.info("Intent topic: [{0}]".format(msg.topic))
        pixel_ring.set_color(r=200, g=133)
        time.sleep(1)
        pixel_ring.off()
    elif msg.topic.startswith('hermes/intent/'):
        logger.info("Intent topic: [{0}]".format(msg.topic))
        pixel_ring.set_color(r=255, g=255)
        time.sleep(1)
        pixel_ring.off()
示例#15
0
 def on_thinking(self):
     print("===== on_thinking =====")
     self.state = 'thinking'
     pixel_ring.think()
示例#16
0
def main():
    logging.basicConfig(level=logging.DEBUG)
    #logging.getLogger('avs.alexa').setLevel(logging.INFO)
    logging.getLogger('hpack.hpack').setLevel(logging.INFO)

    if os.geteuid() != 0:
        time.sleep(1)

    src = RespeakerdSource()
    alexa = Alexa()
    ctl = VolumeCtl()
    power = LED(5)
    power.on()
    src.link(alexa)

    pixel_ring.think()

    state = 'thinking'
    last_dir = 0

    def on_ready():
        global state
        print("===== on_ready =====\r\n")
        state = 'off'
        pixel_ring.off()
        src.on_cloud_ready()

    def on_listening():
        global state
        global last_dir
        print("===== on_listening =====\r\n")
        if state != 'detected':
            print('The last dir is {}'.format(last_dir))
            pixel_ring.wakeup(last_dir)
        state = 'listening'
        pixel_ring.listen()

    def on_speaking():
        global state
        print("===== on_speaking =====\r\n")
        state = 'speaking'
        src.on_speak()
        pixel_ring.speak()

    def on_thinking():
        global state
        print("===== on_thinking =====\r\n")
        state = 'thinking'
        src.stop_capture()
        pixel_ring.think()

    def on_off():
        global state
        print("===== on_off =====\r\n")
        state = 'off'
        pixel_ring.off()

    def on_detected(dir, index):
        global state
        global last_dir
        logging.info('detected hotword:{} at {}`'.format(index, dir))
        state = 'detected'
        last_dir = (dir + 360 - 60) % 360
        alexa.listen()
        pixel_ring.wakeup(last_dir)

    def on_vad():
        # when someone is talking
        # print("."),
        # sys.stdout.flush()
        pass

    def on_silence():
        # when it is silent
        pass

    alexa.state_listener.on_listening = on_listening
    alexa.state_listener.on_thinking = on_thinking
    alexa.state_listener.on_speaking = on_speaking
    alexa.state_listener.on_finished = on_off
    alexa.state_listener.on_ready = on_ready

    alexa.Speaker.CallbackSetVolume(ctl.setVolume)
    alexa.Speaker.CallbackGetVolume(ctl.getVolume)
    alexa.Speaker.CallbackSetMute(ctl.setMute)

    src.set_callback(on_detected)
    src.set_vad_callback(on_vad)
    src.set_silence_callback(on_silence)

    src.recursive_start()

    is_quit = threading.Event()

    def signal_handler(signal, frame):
        print('Quit')
        is_quit.set()

    signal.signal(signal.SIGINT, signal_handler)

    while not is_quit.is_set():
        try:
            time.sleep(1)
        except SyntaxError:
            pass
        except NameError:
            pass

    src.recursive_stop()
    power.off()
示例#17
0
 def think(self) -> None:
     """Show think interaction."""
     pixel_ring.think()
示例#18
0
 def handle_listener_think(self, message):
     self.log.info("Pixel Ring: Think")
     pixel_ring.think()
示例#19
0
 def handle_listener_think(self, message):
     LOG.debug("think")
     pixel_ring.think()
示例#20
0
def start():
    pixel_ring.think()
示例#21
0
 def on_thinking():
     global state
     print("===== on_thinking =====\r\n")
     state = 'thinking'
     src.stop_capture()
     pixel_ring.think()
示例#22
0
def main():
    logging.basicConfig(level=logging.DEBUG)
    #logging.getLogger('avs.alexa').setLevel(logging.INFO)
    logging.getLogger('hpack.hpack').setLevel(logging.INFO)

    en = mraa.Gpio(12)
    if os.geteuid() != 0:
        time.sleep(1)
    en.dir(mraa.DIR_OUT)
    en.write(0)

    src = RespeakerdSource()
    alexa = Alexa()

    src.link(alexa)

    pixel_ring.think()

    state = 'thinking'
    last_dir = 0

    def on_ready():
        global state
        print("===== on_ready =====\r\n")
        state = 'off'
        pixel_ring.off()
        src.on_cloud_ready()

    def on_listening():
        global state
        global last_dir
        print("===== on_listening =====\r\n")
        if state != 'detected':
            print('The last dir is {}'.format(last_dir))
            pixel_ring.wakeup(last_dir)
        state = 'listening'
        pixel_ring.listen()

    def on_speaking():
        global state
        print("===== on_speaking =====\r\n")
        state = 'speaking'
        src.on_speak()
        pixel_ring.speak()

    def on_thinking():
        global state
        print("===== on_thinking =====\r\n")
        state = 'thinking'
        src.stop_capture()
        pixel_ring.think()

    def on_off():
        global state
        print("===== on_off =====\r\n")
        state = 'off'
        pixel_ring.off()

    def on_detected(dir):
        global state
        global last_dir
        logging.info('detected at {}`'.format(dir))
        state = 'detected'
        last_dir = (dir + 360 - 60) % 360
        pixel_ring.wakeup(last_dir)
        alexa.listen()

    alexa.state_listener.on_listening = on_listening
    alexa.state_listener.on_thinking = on_thinking
    alexa.state_listener.on_speaking = on_speaking
    alexa.state_listener.on_finished = on_off
    alexa.state_listener.on_ready = on_ready

    src.set_callback(on_detected)

    src.recursive_start()

    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.recursive_stop()

    en.write(1)
 def handle_listener_think(self, message):
     pixel_ring.think()
示例#24
0
def main():
    logging.basicConfig(level=logging.DEBUG)
    #logging.getLogger('avs.alexa').setLevel(logging.INFO)
    logging.getLogger('hpack.hpack').setLevel(logging.INFO)

    en = mraa.Gpio(12)
    if os.geteuid() != 0:
        time.sleep(1)
    en.dir(mraa.DIR_OUT)
    en.write(0)

    src = RespeakerdSource()
    alexa = Alexa()

    src.link(alexa)

    pixel_ring.think()

    def on_ready():
        global state
        print("===== on_ready =====\r\n")
        state = 'off'
        pixel_ring.off()
        src.on_cloud_ready()

    def on_listening():
        global state
        global last_dir
        print("===== on_listening =====\r\n")
        if state != 'detected':
            print('The last dir is {}'.format(last_dir))
            pixel_ring.wakeup(last_dir)
        state = 'listening'
        pixel_ring.listen()

    def on_speaking():
        global state
        print("===== on_speaking =====\r\n")
        state = 'speaking'
        src.on_speak()
        pixel_ring.speak()

    def on_thinking():
        global state
        print("===== on_thinking =====\r\n")
        state = 'thinking'
        src.stop_capture()
        pixel_ring.think()

    def on_off():
        global state
        print("===== on_off =====\r\n")
        state = 'off'
        pixel_ring.off()

    def on_detected(dir, index):
        global state
        logging.info('detected at {}`'.format(dir))
        state = 'detected'
        pixel_ring.wakeup(dir + 300)
        next_dir = (dir + 60) % 360
        # alexa.listen()
        # set the direction to next beam
        src.on_set_direction(next_dir)

    alexa.state_listener.on_listening = on_listening
    alexa.state_listener.on_thinking = on_thinking
    alexa.state_listener.on_speaking = on_speaking
    alexa.state_listener.on_finished = on_off
    alexa.state_listener.on_ready = on_ready

    src.set_callback(on_detected)

    src.recursive_start()

    is_quit = threading.Event()

    def signal_handler(signal, frame):
        print('Quit')
        is_quit.set()

    signal.signal(signal.SIGINT, signal_handler)

    count = 0
    while not is_quit.is_set():
        try:
            time.sleep(1)
            count += 10
        except SyntaxError:
            pass
        except NameError:
            pass

    src.recursive_stop()

    en.write(1)
示例#25
0
def main():

    # enable led power
    en = mraa.Gpio(12)
    if os.geteuid() != 0:
        time.sleep(1)
    en.dir(mraa.DIR_OUT)
    en.write(0)

    pixel_ring.set_brightness(100)
    pixel_ring.think()

    sm = StateMachine()

    def bus_handler(sender, object, iface, signal, params):
        # print(sender)
        # print(object)
        # print(signal)
        # print(params)

        if signal == 'trigger':
            try:
                dir = params[0]
            except:
                dir = 0
            sm.on_detected(dir)
        elif signal == 'on_listen':
            sm.on_listening()
        elif signal == 'on_think':
            sm.on_thinking()
        elif signal == 'on_speak':
            sm.on_speaking()
        elif signal == 'on_idle':
            sm.on_idle()
        elif signal == 'connecting':
            sm.on_thinking()
        elif signal == 'ready':
            sm.on_avs_ready()
        elif signal == 'respeakerd_ready':
            sm.on_respeakerd_ready()

    system_bus = SystemBus()
    loop = GLib.MainLoop()
    sub = system_bus.subscribe(iface='respeakerd.signal',
                               signal_fired=bus_handler)

    def on_exit(sig):
        sub.unsubscribe()
        loop.quit()

    setup_signals(signals=[signal.SIGINT, signal.SIGTERM, signal.SIGHUP],
                  handler=on_exit)

    print("Running...")

    try:
        loop.run()
    except KeyboardInterrupt:
        pass
    finally:
        pixel_ring.off()

    print("Quit...")

    en.write(1)
from pixel_ring import pixel_ring
import mraa
import os

en = mraa.Gpio(12)
if os.geteuid() != 0:
    time.sleep(1)

en.dir(mraa.DIR_OUT)
en.write(0)

if __name__ == '__main__':
    while True:

        try:
            pixel_ring.wakeup()
            time.sleep(3)
            pixel_ring.think()
            time.sleep(3)
            pixel_ring.speak()
            time.sleep(6)
            pixel_ring.off()
            time.sleep(3)
        except KeyboardInterrupt:
            break

    pixel_ring.off()
    time.sleep(1)

en.write(1)
示例#27
0
def think(n):
    time_end = start_LED(n)
    pixel_ring.wakeup()
    pixel_ring.think()
    time.sleep(n)
    end_LED()