def main(): src = Source(rate=16000, channels=4) ch1 = ChannelPicker(channels=4, pick=1) kws = KWS() doa = DOA(rate=16000) src.link(ch1) ch1.link(kws) src.link(doa) outf = "./log/test.wav" fsall = FileSink(outf, rate=16000, channels=4) src.link(fsall) #ch1.link(fs) for i in range(4): ch = ChannelPicker(channels=4, pick=i) src.link(ch) outf = "./log/test"+str(i)+".wav" fs = FileSink(outf, rate=16000, channels=1) ch.link(fs) def on_detected(keyword): print('detected {} at direction {}'.format(keyword, doa.get_direction())) kws.set_callback(on_detected) src.recursive_start() sec = 0 while sec < 5: try: time.sleep(1) sec = sec + 1 except KeyboardInterrupt: break src.recursive_stop()
def main(): if len(sys.argv) < 2: print('Usage: {} audio.wav') sys.exit(1) src = Source(sys.argv[1]) ch0 = ChannelPicker(channels=src.channels, pick=0) kws = KWS() doa = DOA(rate=16000) src.link(ch0) ch0.link(kws) src.link(doa) def on_detected(keyword): print('detected {} at direction {}'.format(keyword, doa.get_direction())) kws.set_callback(on_detected) src.recursive_start() while src.is_active(): try: time.sleep(1) except KeyboardInterrupt: break src.recursive_stop() # wait a second to allow other threads to exit time.sleep(1)
def main(): src = Source(rate=16000, channels=4, frames_size=320) ch1 = ChannelPicker(channels=4, pick=1) kws = KWS() doa = DOA(rate=16000) src.link(ch1) ch1.link(kws) src.link(doa) def on_detected(keyword): position = doa.get_direction() pixels.wakeup(position) print('detected {} at direction {}'.format(keyword, position)) kws.set_callback(on_detected) src.recursive_start() while True: try: time.sleep(1) except KeyboardInterrupt: print('STOP') break src.recursive_stop()
def main(): ard = serial.Serial('/dev/ttyACM0', 9600) src = Source(rate=16000, channels=8) ch1 = ChannelPicker(channels=8, pick=1) kws = KWS() doa = DOA(rate=16000) time.sleep(1) src.link(ch1) ch1.link(kws) src.link(doa) while True: def on_detected(keyword): direction = doa.get_direction() print('detected {} at direction {}'.format(keyword, )) if (direction >= 0) and (direction <= 180): ard.write(struct.pack('>B', direction)) kws.set_callback(on_detected) src.recursive_start() while True: try: time.sleep(1) except KeyboardInterrupt: break src.recursive_stop()
def main(): logging.basicConfig(level=logging.DEBUG) src = Source(rate=16000, channels=8) ch1 = ChannelPicker(channels=8, pick=1) ns = NS(rate=16000, channels=1) kws = KWS(model='alexa') doa = DOA(rate=16000) alexa = Alexa() src.link(ch1) ch1.link(ns) ns.link(kws) kws.link(alexa) src.link(doa) def on_detected(keyword): logging.info('detected {} at direction {}'.format( keyword, doa.get_direction())) alexa.listen() kws.set_callback(on_detected) src.recursive_start() while True: try: time.sleep(1) except KeyboardInterrupt: break src.recursive_stop()
def main(): src = Source('/tmp/ec.output', rate=16000, channels=2) ch0 = ChannelPicker(channels=src.channels, pick=1) ns = NS() kws = KWS(model='alexa', sensitivity=0.7) alexa = Alexa() src.pipeline(ch0, ns, kws, alexa) def on_detected(keyword): print('detected {}'.format(keyword)) alexa.listen() kws.set_callback(on_detected) alexa.state_listener.on_listening = pixels.listen alexa.state_listener.on_thinking = pixels.think alexa.state_listener.on_speaking = pixels.speak alexa.state_listener.on_finished = pixels.off src.pipeline_start() is_quit = [] def signal_handler(sig, frame): is_quit.append(True) print('quit') signal.signal(signal.SIGINT, signal_handler) while src.is_active() and not is_quit: time.sleep(1) src.pipeline_stop()
def main(): if len(sys.argv) < 2: print('Usage: {} audio.wav') sys.exit(1) src = Source(sys.argv[1]) ch0 = ChannelPicker(channels=src.channels, pick=0) ns = NS(rate=src.rate, channels=1) kws = KWS() src.pipeline(ch0, kws) # src.pipeline(ch0, ns, kws) def on_detected(keyword): print('detected {}'.format(keyword)) kws.set_callback(on_detected) src.pipeline_start() while True: try: time.sleep(1) except KeyboardInterrupt: break src.pipeline_stop() # wait a second to allow other threads to exit time.sleep(1)
def main(): src = Source(rate=16000, channels=8) ch1 = ChannelPicker(channels=8, pick=1) ns = NS(rate=16000, channels=1) kws = KWS() doa = DOA(rate=16000) src.link(ch1) ch1.link(ns) ns.link(kws) src.link(doa) def on_detected(keyword): print('detected {} at direction {}'.format(keyword, doa.get_direction())) kws.set_callback(on_detected) src.recursive_start() while True: try: time.sleep(1) except KeyboardInterrupt: break src.recursive_stop()
def main(): logging.basicConfig(level=logging.DEBUG) src = Source(rate=16000) ns = NS(rate=16000, channels=1) kws = KWS() alexa = Alexa(model='alexa') src.link(ns) ns.link(kws) kws.link(alexa) def on_detected(keyword): logging.info('detected {}'.format(keyword)) alexa.listen() kws.set_callback(on_detected) src.recursive_start() while True: try: time.sleep(1) except KeyboardInterrupt: break src.recursive_stop()
def main(): src = Source(rate=16000, channels=8) ch1 = ChannelPicker(channels=8, pick=1) kws = KWS() filename = '4.kws.' + datetime.datetime.now().strftime( "%Y%m%d.%H:%M:%S") + '.wav' sink = FileSink(filename, channels=src.channels, rate=src.rate) src.link(sink) src.pipeline(ch1, kws) def on_detected(keyword): print('detected {}'.format(keyword)) kws.set_callback(on_detected) src.recursive_start() while True: try: time.sleep(1) except KeyboardInterrupt: break src.recursive_stop()
def main(): import time from voice_engine.source import Source from voice_engine.kws import KWS src = Source(rate=16000, channels=2, frames_size=1600) route = Route(channels=src.channels) kws = [] def gen(channel): def on_detected(keyword): print('detected at channel {}'.format(channel)) return on_detected for ch in range(src.channels): k = KWS(sensitivity=0.5) k.set_callback(gen(ch)) kws.append(k) src.pipeline(route, kws) src.pipeline_start() while True: try: time.sleep(1) except KeyboardInterrupt: break src.pipeline_stop()
def main(): import time from voice_engine.channel_picker import ChannelPicker from voice_engine.kws import KWS from voice_engine.source import Source src = Source(channels=2) ch0 = ChannelPicker(channels=src.channels, pick=0) kws = KWS(model='snowboy', sensitivity=0.7) bing = Bing(BING_KEY) src.pipeline(ch0, kws, bing) def on_detected(keyword): print('detected {}'.format(keyword)) bing.listen() kws.set_callback(on_detected) src.recursive_start() while True: try: time.sleep(1) except KeyboardInterrupt: break src.recursive_stop()
def main(): src = Source(rate=16000, channels=2) ch1 = ChannelPicker(channels=2, pick=1) ns = NS(rate=16000, channels=1) kws = KWS(model='snowboy', sensitivity=0.6, verbose=True) src.pipeline(ch1, ns, kws) def on_detected(keyword): print('detected {}'.format(keyword)) kws.set_callback(on_detected) src.pipeline_start() while True: try: time.sleep(1) except KeyboardInterrupt: break src.pipeline_stop() # wait a second to allow other threads to exit time.sleep(1)
def main(): logging.basicConfig(level=logging.DEBUG) src = Source(rate=16000) ns = NS(rate=16000, channels=1) kws = KWS(model='alexa') alexa = Alexa() alexa.state_listener.on_listening = pixel_ring.listen alexa.state_listener.on_thinking = pixel_ring.think alexa.state_listener.on_speaking = pixel_ring.speak alexa.state_listener.on_finished = pixel_ring.off src.pipeline(ns, kws, alexa) def on_detected(keyword): logging.info('detected {}'.format(keyword)) alexa.listen() kws.set_callback(on_detected) is_quit = [] def signal_handler(signal, frame): is_quit.append(True) print('Quit') signal.signal(signal.SIGINT, signal_handler) src.pipeline_start() while not is_quit: try: time.sleep(1) except KeyboardInterrupt: break src.pipeline_stop()
def main(): logging.basicConfig(level=logging.DEBUG) src = Source(rate=16000, frames_size=320) kws = KWS(model='alexa', sensitivity=0.8) alexa = Alexa() alexa.state_listener.on_listening = pixels.listen alexa.state_listener.on_thinking = pixels.think alexa.state_listener.on_speaking = pixels.speak alexa.state_listener.on_finished = pixels.off src.link(kws) kws.link(alexa) def on_detected(keyword): logging.info('detected {}'.format(keyword)) alexa.listen() kws.set_callback(on_detected) src.recursive_start() while True: try: time.sleep(1) except KeyboardInterrupt: break src.recursive_stop()
def main(): src = Source(rate=16000, channels=4, frames_size=320) ch0 = ChannelPicker(channels=4, pick=0) kws = KWS(model='snowboy', sensitivity=0.6, verbose=True) doa = DOA(rate=16000) src.link(ch0) ch0.link(kws) src.link(doa) def on_detected(keyword): position = doa.get_direction() pixels.wakeup(position) print('detected {} at direction {}'.format(keyword, position)) kws.set_callback(on_detected) src.recursive_start() while True: try: time.sleep(1) except KeyboardInterrupt: break src.recursive_stop()
def main(): src = Source(rate=16000, channels=4) ch0 = ChannelPicker(channels=src.channels, pick=0) kws = KWS(model='snowboy', sensitivity=0.6, verbose=True) doa = DOA(rate=16000) src.link(ch0) ch0.link(kws) src.link(doa) def on_detected(keyword): print('detected {} at direction {}'.format(keyword, doa.get_direction())) kws.set_callback(on_detected) src.recursive_start() while True: try: time.sleep(1) except KeyboardInterrupt: break src.recursive_stop() # wait a second to allow other threads to exit time.sleep(1)
def main(): src = Source(rate=16000, channels=4, frames_size=320) ch1 = ChannelPicker(channels=4, pick=1) kws = KWS(model='dad.pmdl') doa = DOA(rate=16000) src.link(ch1) ch1.link(kws) src.link(doa) def on_detected(keyword): position = doa.get_direction() pixels.wakeup(position) print('detected {} at direction {}'.format(keyword, position)) kws.set_callback(on_detected) src.recursive_start() while True: try: time.sleep(1) except KeyboardInterrupt: break src.recursive_stop()
def main(): ## RESPEAKER_RATE = 16000 ## RESPEAKER_CHANNELS = 1 ## RESPEAKER_WIDTH = 2 ## CHUNK = 1024 ## RECORD_SECONDS = 2 src = Source(rate=16000, channels=4, frames_size=320) ch1 = ChannelPicker(channels=4, pick=1) kws = KWS() doa = DOA(rate=16000) src.link(ch1) ch1.link(kws) src.link(doa) def on_detected(keyword): position = doa.get_direction() pixels.wakeup(position) print('detected {} at direction {}'.format(keyword, position)) src.stream.start() print("* recording") frames = [] for i in range(0, int(RESPEAKER_RATE / CHUNK * RECORD_SECONDS)): data = stream.read(CHUNK) frames.append(data) print("* done recording") src.stream.stop() print("start to send to baidu") # audio_data should be raw_data text = baidu.server_api(generator_list(frames)) if text: try: text = json.loads(text) for t in text['result']: print(t) except KeyError: print("get nothing") else: print("get nothing") kws.set_callback(on_detected) src.recursive_start() while True: try: time.sleep(1) except KeyboardInterrupt: break src.recursive_stop()
class StateMachine: def __init__(self, wake_word_model): self.__src = Source(rate=16000) self.__ns = NS(rate=16000, channels=1) self.__kws = KWS(model=wake_word_model) self.__alexa = Alexa() self.__src.link(self.__ns) self.__ns.link(self.__kws) self.__kws.link(self.__alexa) self.__pixels = ThreePixels() self.__button = Button() self.__alexa.state_listener.on_listening = self.on_listening self.__alexa.state_listener.on_thinking = self.on_thinking self.__alexa.state_listener.on_speaking = self.on_speaking self.__alexa.state_listener.on_finished = self.on_finished def on_listening(self): self.__pixels.wakeup() def on_thinking(self): self.__pixels.think() def on_speaking(self): self.__pixels.speak() def on_finished(self): self.__pixels.off() def __on_detected(self, keyword): print('detected {}'.format(keyword)) print('Alexa is listening!') self.__alexa.listen() def __pushed_button(self, channel): print('button pushed') print('Alexa is listening!') self.__alexa.listen() def start(self): print('starting voice engine') self.__kws.set_callback(self.__on_detected) Button.set_callback_on_rising(self.__pushed_button) self.__src.recursive_start() def stop(self): print('stopping voice engine') self.__src.recursive_stop() Button.clean_up() self.__pixels.off()
def t3_bot(): src = Source(rate=16000, channels=4, frames_size=320) ch1 = ChannelPicker(channels=4, pick=1) kws = KWS() doa = DOA(rate=16000) src.link(ch1) ch1.link(kws) src.link(doa) pixels.listen() pwm.setPWM(0, 0, 370) pwm.setPWM(1, 0, 640) counter = 0 def on_detected(keyword): position = doa.get_direction() pixels.wakeup(position) print('detected {} at direction {}'.format(keyword, position)) if position >= 30 and position <= 180: pwm.setPWM(0, 0, 175) pwm.setPWM(1, 0, 500) elif position > 180 and position <= 330: pwm.setPWM(0, 0, 560) pwm.setPWM(1, 0, 500) elif position > 330 or position < 30: pwm.setPWM(0, 0, 370) pwm.setPWM(1, 0, 6200) else: pwm.setPWM(0, 0, 370) pwm.setPWM(1, 0, 640) #talkassist.os.system("espeak 'may i help you'") print("How may I help you?") print("call google assistant here, delete this line.") kws.set_callback(on_detected) src.recursive_start() while True: try: time.sleep(1) counter += 1 print("counter is at " + str(counter)) except KeyboardInterrupt: break src.recursive_stop()
def main(): src = Source(rate=16000, channels=1, device_name="default") kws = KWS(model='computer', sensitivity=0.6, verbose=True) src.pipeline(kws) def on_detected(keyword): print('\ndetected {}'.format(keyword)) kws.set_callback(on_detected) src.pipeline_start() while True: try: time.sleep(1) except KeyboardInterrupt: break src.pipeline_stop()
def main(): src = Source('/tmp/ec.output', rate=16000, channels=2) ch0 = ChannelPicker(channels=src.channels, pick=1) kws = KWS(sensitivity=0.7) src.pipeline(ch0, kws) def on_detected(keyword): print('detected {}'.format(keyword)) kws.set_callback(on_detected) src.pipeline_start() while src.is_active(): try: time.sleep(1) except KeyboardInterrupt: break src.pipeline_stop()
def main(): ser = serial.Serial("/dev/ttyACM0", 9600) src = Source(rate=16000, channels=4, frames_size=320) ch1 = ChannelPicker(channels=4, pick=1) kws = KWS(model='dad.pmdl') doa = DOA(rate=16000) src.link(ch1) ch1.link(kws) src.link(doa) def on_detected(keyword): position = doa.get_direction() pixels.wakeup(position) print('detected {} at direction {}'.format(keyword, position)) if position <= 90: ser.write(b"1000\n") elif position > 90 and position <= 180: ser.write(b"0100\n") elif position > 180 and position <= 270: ser.write(b"0010\n") else: ser.write(b"0001\n") vibrate_time = 0.5 time.sleep(vibrate_time) ser.write(b"0000\n") kws.set_callback(on_detected) src.recursive_start() while True: try: time.sleep(1) except KeyboardInterrupt: break src.recursive_stop() ser.close()
def main(): logging.basicConfig(level=logging.DEBUG) src = Source(rate=16000, channels=4, device_name='default') ds = DelaySum(channels=src.channels) ns = NS(rate=16000, channels=1) kws = KWS(model='alexa') alexa = Alexa() alexa.state_listener.on_listening = leds_on # alexa.state_listener.on_thinking = pixel_ring.think # alexa.state_listener.on_speaking = pixel_ring.speak alexa.state_listener.on_finished = leds_off src.link(ds) ds.link(ns) ns.link(kws) kws.link(alexa) def on_detected(keyword): logging.info('\ndetected {}'.format(keyword)) alexa.listen() kws.set_callback(on_detected) is_quit = [] def signal_handler(sig, frame): is_quit.append(True) print('quit') signal.signal(signal.SIGINT, signal_handler) src.pipeline_start() while not is_quit: time.sleep(1) src.pipeline_stop()
logging.basicConfig(level=logging.WARNING) src = Source(rate=16000) kws = KWS(model='alexa', sensitivity=0.5) alexa = Alexa() src.pipeline(kws, alexa) def on_detected(keyword): print('detected {}'.format(keyword)) alexa.listen() kws.set_callback(on_detected) is_quit = [] def signal_handler(signal, frame): print('Quit') is_quit.append(True) signal.signal(signal.SIGINT, signal_handler) src.pipeline_start() while not is_quit: time.sleep(1) src.pipeline_stop()