def initialize(self): LOG.debug("initialising") self.en = mraa.Gpio(12) if os.geteuid() != 0: time.sleep(1) self.en.dir(mraa.DIR_OUT) self.en.write(0) pixel_ring.set_brightness(20) pixel_ring.wakeup() self.userkey = None try: self.userkey = InputDevice("/dev/input/event0") except Exception as e: LOG.debug("exception while reading InputDevice: {}".format(e)) if self.userkey: self.schedule_repeating_event(self.handle_button, None, 0.1, 'RespeakerIo') self.add_event('recognizer_loop:record_begin', self.handle_listener_wakeup) self.add_event('recognizer_loop:record_end', self.handle_listener_off) self.add_event('recognizer_loop:audio_output_start', self.handle_listener_speak) self.add_event('recognizer_loop:audio_output_end', self.handle_listener_off) self.add_event('mycroft.skill.handler.start', self.handle_listener_think) self.add_event('mycroft.skill.handler.complete', self.handle_listener_off) pixel_ring.off()
def on_detected(keyword): print('ALEXA Testing fuction') direction = doa.get_direction() print('detected {} at direction {}'.format(keyword, direction)) alexa.listen() pixel_ring.wakeup(direction) print('afteralexa')
def startup(self): """Startup of the LED pixel ring.""" LOG.debug("[Respeaker4Mic] Start LED pixel ring.") self.power.on() pixel_ring.set_brightness(10) pixel_ring.change_pattern(self.pattern) pixel_ring.wakeup()
def main(): vad = webrtcvad.Vad(3) speech_count = 0 chunks = [] doa_chunks = int(DOA_FRAMES / VAD_FRAMES) try: with MicArray(RATE, CHANNELS, RATE * VAD_FRAMES / 1000) as mic: for chunk in mic.read_chunks(): # Use single channel audio to detect voice activity if vad.is_speech(chunk[0::CHANNELS].tobytes(), RATE): speech_count += 1 sys.stdout.write('1') else: sys.stdout.write('0') sys.stdout.flush() chunks.append(chunk) if len(chunks) == doa_chunks: if speech_count > (doa_chunks / 2): frames = np.concatenate(chunks) direction = mic.get_direction(frames) pixel_ring.wakeup(direction) print('\n{}'.format(int(direction))) speech_count = 0 chunks = [] except KeyboardInterrupt: pass pixel_ring.off()
def initialize(self): self.log.info("Pixel Ring: Initializing") self.power = LED(5) self.power.on() pixel_ring.set_brightness(10) pixel_ring.change_pattern('echo') pixel_ring.wakeup() self.enable()
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_detected(keyword): direction = doa.get_direction() print('PWS Testing') print('detected {} at direction {}'.format(keyword, direction)) pwstest() #alexa.listen() pixel_ring.wakeup(direction) print('Personal function working')
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()
def on_listening(self): print("===== on_listening =====") if self.state != 'detected': print('pointing to last dir...') pixel_ring.wakeup(self.last_dir) print("") self.state = 'listening' pixel_ring.listen()
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)
def jarvis_parse_audio(audio): pixel_ring.wakeup() word_list = collect_word_list(audio) if word_list: parse_command_module(word_list) else: pixel_ring.off() time.sleep(1) power.off()
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 init_pixelring(): power = mraa.Gpio(12) time.sleep(1) power.dir(mraa.DIR_OUT) power.write(0) pixel_ring.wakeup(0) time.sleep(1) 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)
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()
def on_detected(self, dir): print('===== on_detected =====\r\n@ {}`'.format(dir)) if self.state in ['listening', 'thinking']: print( 'invalid trigger, reason: listening or thinking can not be interrupted!' ) return self.state = 'detected' self.last_dir = (dir + 360 - 60) % 360 pixel_ring.wakeup(self.last_dir)
def initialize(self): self.log.info("Pixel Ring: Initializing") self.power = LED(5) self.power.on() pixel_ring.set_brightness(10) pattern = self.settings.get("theme", "mytheme1") pixel_ring.change_pattern(pattern) self.log.info( f"Pixel Ring Pattern - Input: {pattern} - Actual: {pixel_ring.pattern}" ) pixel_ring.wakeup() self.enable()
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
def start_listening(): mic = sr.Microphone() with mic as source: print("jarvis is listening") pixel_ring.wakeup() audio = r.listen(source, timeout=2) word_list = collect_word_list(audio) if word_list: print("found a word list") parse_command_module(word_list) else: pixel_ring.off() time.sleep(1) power.off()
def led_pixel_ring(): pixel_ring.set_brightness(20) while led_ring: try: pixel_ring.wakeup() time.sleep(0.1) pixel_ring.off() time.sleep(0.1) pixel_ring.off() except KeyboardInterrupt: break pixel_ring.off()
def led_pixel_ring(): en.dir(mraa.DIR_OUT) en.write(0) pixel_ring.set_brightness(20) while led_ring: try: pixel_ring.wakeup() time.sleep(0.01) pixel_ring.off() time.sleep(0.01) except KeyboardInterrupt: break pixel_ring.off() en.write(1)
def initialize(self): LOG.debug("initialising") pixel_ring.set_brightness(10) pixel_ring.wakeup() self.add_event('recognizer_loop:record_begin', self.handle_listener_wakeup) self.add_event('recognizer_loop:record_end', self.handle_listener_off) self.add_event('recognizer_loop:audio_output_start', self.handle_listener_speak) self.add_event('recognizer_loop:audio_output_end', self.handle_listener_off) self.add_event('mycroft.skill.handler.start', self.handle_listener_think) self.add_event('mycroft.skill.handler.complete', self.handle_listener_off) pixel_ring.off()
def run(self): has_voice = 0 buffer = '' count = 0 pixel_ring_countdown = 0 while not self.done: data = self.queue.get() buffer += data while len(buffer) >= self.frame_bytes: data = buffer[:self.frame_bytes] buffer = buffer[self.frame_bytes:] data = np.fromstring(data, dtype='int16') mono = data[0::self.channels].tostring() mono = self.ap.process_stream(mono) has_voice = self.ap.has_voice() # sys.stdout.write('1' if has_voice else '0') # sys.stdout.flush() offset, direction = self._process(data) self.collections.append([direction, offset, has_voice]) count += 1 if count >= self.collections.maxlen: direction = self.get_direction() if direction: print('@ {}'.format(direction)) pixel_ring.wakeup(direction) pixel_ring_countdown = 10 else: if pixel_ring_countdown > 0: pixel_ring_countdown -= 1 if pixel_ring_countdown == 0: pixel_ring.off() count = 0 super(DOA, self).put(mono)
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()
def on_detected(keyword): direction = doa.get_direction() print('detected {} at direction {}'.format(keyword, direction)) pixel_ring.wakeup(direction)
""" import pyaudio import signal import time from voice_engine.element import Element # from voice_engine.source import Source from voice_engine.kws import KWS from voice_engine.channel_picker import ChannelPicker from voice_engine.doa_respeaker_v2_6mic_array import DOA from avs.alexa import Alexa from pixel_ring import pixel_ring pixel_ring.change_pattern('echo') pixel_ring.wakeup(0) time.sleep(1) pixel_ring.off() class Source(Element): def __init__(self, rate=16000, frames_size=None, channels=6, device_name=''): super(Source, self).__init__() self.rate = rate self.frames_size = frames_size if frames_size else rate / 100
def handle_listener_wakeup(self, message): LOG.debug("wakeup") pixel_ring.wakeup()
def handle_listener_wakeup(self, message): self.log.info("wakeup") pixel_ring.wakeup()
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)
def Led_lighton(self, dir): pixel_ring.wakeup(dir)