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(): 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) 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(): 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(): 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(): 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(): 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) src.link(ch1) ch1.link(ns) ns.link(kws) src.link(doa) def on_detected(keyword): direction = doa.get_direction() logging.info('detected {} at direction {}'.format(keyword, direction)) pixels.wakeup(direction) kws.on_detected = on_detected src.recursive_start() while True: try: time.sleep(0.05) #direction = doa.get_direction() #logging.info('direction {}'.format(direction)) #pixels.wakeup(direction) 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()
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 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(): import time import datetime from voice_engine.source import Source from voice_engine.channel_picker import ChannelPicker from voice_engine.file_sink import FileSink src = Source(channels=2, rate=48000, frames_size=48000) chx = ChannelPicker(channels=src.channels, pick=0) thd = THD(1000, src.rate) filename = '2.94dB1KHz.' + 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(chx, thd) src.pipeline_start() while True: try: time.sleep(1) except KeyboardInterrupt: break src.pipeline_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.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(): 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('/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(): src = Source(rate=16000, frames_size=320, channels=8) ch0 = ChannelPicker(channels=src.channels, pick=0) kws = KWS(model='snowboy', sensitivity=0.5) doa = DOA(rate=src.rate, chunks=20) src.pipeline(ch0, kws) src.link(doa) def on_detected(keyword): direction = doa.get_direction() print('detected {} at direction {}'.format(keyword, direction)) pixel_ring.wakeup(direction) time.sleep(2) pixel_ring.off() kws.on_detected = 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()
def main(): logging.basicConfig(level=logging.WARNING) # logging.basicConfig(level=logging.WARNING) logging.getLogger('hpack.hpack').setLevel(logging.INFO) # logging.getLogger('voice_engine.netT').setLevel(logging.DEBUG) # src = Source(rate=16000, frames_size=320, channels=6) src = Source(rate=16000, frames_size=128, channels=6, device_name='ReSpeaker 4 Mic Array') ch0 = ChannelPicker(channels=src.channels, pick=0) nett = NetT() src.pipeline(ch0, nett) 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()
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 __init__(self): self.init_pixelring() self.source = Source(rate=160000, frames_size=320, channels=8) self.ch0 = ChannelPicker(channels=self.source.channels, pick=0) self.kws = KWS(sensitivity=0.7) self.doa = DOA(rate=self.source.rate, chunks=20) self.kws.on_detected = self.kws_on_detected self.cmd_pub = rospy.Publisher('/respeaker/cmd', String, queue_size=1)
def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.setWindowTitle('Audio Measuring Experiment') self.resize(800, 500) self.cwidget = QWidget() self.setCentralWidget(self.cwidget) layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.cwidget.setLayout(layout) self.plotwidget = pg.PlotWidget() layout.addWidget(self.plotwidget) self.plotwidget.setTitle(title="press 'space' to freeze/resume") self.plot = self.plotwidget.plot() self.plot.setPen((0, 255, 0)) self.ff = pg.TextItem('fundamental frequency', anchor=(0, 0)) self.plotwidget.addItem(self.ff) self.ff.setPos(100, 0) self.arrow = pg.ArrowItem(pos=(100, 0), angle=-45) self.plotwidget.addItem(self.arrow) plotitem = self.plotwidget.getPlotItem() # plotitem.hideAxis('left') # plotitem.hideAxis('bottom') self.freeze = False self.timer = pg.QtCore.QTimer() self.timer.timeout.connect(self.update) self.timer.start(50) self.src = Source(rate=48000, frames_size=4800) chx = ChannelPicker(channels=self.src.channels, pick=0) thd = THD(1000, self.src.rate) filename = '2.94dB1KHz.' + datetime.datetime.now().strftime( "%Y%m%d.%H:%M:%S") + '.wav' sink = FileSink(filename, channels=self.src.channels, rate=self.src.rate) def on_data(d): global data data = d thd.on_data = on_data self.src.link(sink) self.src.pipeline(thd) self.src.pipeline_start()
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) ch1 = ChannelPicker(channels=4, pick=1) ns = NS(rate=16000, channels=1) kws = KWS(model='snowboy') doa = DOA(rate=16000) 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 def on_detected(keyword): direction = doa.get_direction() logging.info('detected {} at direction {}'.format(keyword, direction)) pixels.wakeup(direction) alexa.listen() kws.on_detected = on_detected src.link(ch1) ch1.link(ns) ns.link(kws) kws.link(alexa) src.link(doa) 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=4) ch1 = ChannelPicker(channels=4, pick=1) ns = NS(rate=16000, channels=1) kws = KWS(model='snowboy') doa = DOA(rate=16000) 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 def on_detected(keyword): direction = doa.get_direction() logging.info('detected {} at direction {}'.format(keyword, direction)) pixels.wakeup(direction) alexa.listen() kws.on_detected = on_detected src.link(ch1) ch1.link(ns) ns.link(kws) kws.link(alexa) src.link(doa) src.recursive_start() while True: try: time.sleep(1) except KeyboardInterrupt: break src.recursive_stop()
def main(): src = Source(rate=16000, frames_size=320, channels=8) # ds = DelaySum(channels=8, frames_size=src.frames_size, max_offset=max_offset) ch0 = ChannelPicker(channels=src.channels, pick=0) kws = KWS() # doa = DOA(rate=16000, chunks=20) 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.link(ch0) ch0.link(kws) kws.link(alexa) # src.link(doa) def on_detected(keyword): # direction = doa.get_direction() alexa.listen() # pixel_ring.wakeup((direction + 0) % 360) # print('detected {} at direction {}'.format(keyword, direction)) print('detected keyword') kws.on_detected = on_detected src.recursive_start() while True: try: time.sleep(1) except KeyboardInterrupt: print('quit') break src.recursive_stop()
def main(): src = Source(rate=16000, frames_size=160, channels=2) ch0 = ChannelPicker(channels=src.channels, pick=0) ns = NS(rate=src.rate, channels=1) kws = KWS() doa = DOA(rate=16000, chunks=50) 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 # data flow between elements # --------------------------- # src -> ns -> kws -> alexa # \ # doa src.pipeline(ch0, ns, kws, alexa) src.link(doa) def on_detected(keyword): direction = doa.get_direction() print('detected {} at direction {}'.format(keyword, direction)) alexa.listen() pixel_ring.wakeup(direction) kws.on_detected = 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() pixel_ring.off() # wait a second to allow other threads to exit time.sleep(1)
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(): # src = Source(rate=16000, frames_size=320, channels=6) src = Source(rate=16000, frames_size=160, channels=6, device_name='hw:1') ch0 = ChannelPicker(channels=src.channels, pick=0) kws = KWS(model='snowboy', sensitivity=0.5) # doa = DOA(rate=src.rate, chunks=20) 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(ch0, kws, alexa) # src.link(doa) def on_detected(keyword): # direction = doa.get_direction() # print('detected {} at direction {}'.format(keyword, direction)) print('detected {} '.format(keyword)) alexa.listen() # pixel_ring.wakeup(direction) kws.on_detected = 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()
''' CTRL + C ''' def CtrlC(signum, frame): os.kill(os.getpid(), signal.SIGKILL) ''' main start ... ''' if __name__ == "__main__": try: src = Source(channels=8) ch0 = ChannelPicker(channels=src.channels, pick=0) ns = NS() bing = Bing(BING_KEY) src.pipeline(ch0, ns, bing) bing_api_call() signal.signal(signal.SIGINT, CtrlC) signal.signal(signal.SIGTERM, CtrlC) thread_key = threading.Thread(target=key_hander, args=(1, )) thread_play = threading.Thread(target=pre_play, args=(1, )) thread_key.setDaemon(True)
def main(): src = Source(rate=16000, channels=1, frames_size=21000) ch1 = ChannelPicker(channels=1, pick=1) # doa = DOA(rate=16000, chunks=3) model_path = get_model_path() config = Decoder.default_config() # config.set_string('-hmm', os.path.join(model_path, 'en-us')) # config.set_string('-lm', os.path.join(model_path, 'en-us.lm.bin')) config.set_string('-hmm', os.path.join(model_path, 'en-us')) config.set_string('-lm', '2823.lm') config.set_string('-verbose', 'False') config.set_string('-dict', '2823.dic') # config.set_string('-dict', os.path.join(model_path, 'cmudict-en-us.dict')) config.set_string('-kws', 'keyphrase.list') config.set_string('-logfn', '/dev/null') # config.set_string('-keyphrase', 'hey there') # config.set_float('-kws_threshold', 1e-30) sphinx = Sphinx(config) src.link(ch1) # src.link(doa) ch1.link(sphinx) graph = XMLParser(graph_file="basic.xml", debug=True).parse() arduino = serial.Serial('/dev/ttyACM0', 57600) arduino.timeout = 0.1 # Check currnet state print("Current State: {}".format(graph.get_current_state().name)) def on_graph_state_change(): print("onStateChange()") # Runs through state responses print("\tNew Current State: {}".format(graph.state)) print("\tExecuting responses for nextState...") if len(graph.state.get_responses()) > 0: print('Responses: {}'.format(len(graph.state.get_responses()))) for response in graph.state.get_responses(): print('\tRunning Response {}'.format(response)) # do response action whether it has to do with moving motors, turning led, etc if response.typ == ResponseType.GO_TO_STATE: graph.set_current_state(response.value) elif response.typ == ResponseType.LED: pixels != null: if response.value == 'listening': pixels.think() elif response.value == 'off': pixels.off() elif response.value == 'hello': pixels.speak() elif response.value == 'following': pixels.following() elif response.value == 'doa': if mic != null: pixels.wakeup(mic.direction) else: print("Unknown LED value: {} was found.".format(response.value)) elif response.typ == ResponseType.MOTOR_MOVE: if response.value == 'forward': arduino.write("d:f;") elif response.value == 'stop': arduino.write("d:s;") elif response.typ == ResponseType.CAMERA_MOVE: if response.value == 'doa': if mic != null: voice_direction = mic.direction print "voice from " + str(voice_direction) arduino_command = "m:" + str(voice_direction) + ";" if voice_direction < 180: #voice is coming from behind voice_direction = (voice_direction + 180) % 360 else: #voice is coming from in front voice_direction = 90 arduino_command = arduino_command + "c:" + str(voice_direction) + ",120;" arduino.write(arduino_command) last_time_motor_moved = simpletime.time() print("@done@") elif response.typ == ResponseType.VOICE_RESPONSE: text = response.value.replace(' ', '_') #Calls the Espeak TTS Engine to read aloud a Text call([cmd_beg+cmd_out+text+cmd_end], shell=True) else: print("Unused response type: {}.".format(response.typ))
class XYRobot(object): jike = config.get('jike', False) src = Source(rate=16000, channels=4, frames_size=320) ch1 = ChannelPicker(channels=4, pick=1) #这里需要填写pmdl的绝对路径 #kws = KWS() #kws = KWS(os.path.join(constants.DATA_PATH ,config.get('kws_file_name',''))) kws = KWS( os.path.join(constants.DATA_PATH, config.get('kws_file_name', ''))) doa = DOA(rate=16000) def __init__(self): print('极客模式:' + str(self.jike)) self.src.link(self.ch1) self.ch1.link(self.kws) self.src.link(self.doa) def on_detected(keyword): position = self.doa.get_direction() pixels.wakeup(position) voice = os.path.join( constants.DATA_PATH, 'sysvoices', 'sysvoice' + str(random.randint(1, 8)) + '.mp3') direction = pixels.positionToDirection() print('detected {} at direction {} is {}'.format( keyword, position, direction)) #这里是唤醒后进行打招呼的语音播放 pixels.speak(voice) print(str(keyword) + voice) record.speech('你在我' + direction) if self.jike: print('进入极客模式') # 创建线程01,不指定参数 thread_01 = Thread(target=instructions.jikeThread, args=( "jikeThread01", record, pixels, )) # 启动线程01 thread_01.start() else: #开始录音 outputtext = record.record() #这里是指令,语音识别后返回文字,将文字传入instructionsFunc,进行处理和播放 instructions.instructionsFunc(outputtext, record, pixels) self.kws.set_callback(on_detected) self.src.recursive_start() config.init() def sigint_handler(self, signum, frame): record.stream.stop_stream() record.stream.close() record.p.terminate() self.src.recursive_stop() print 'catched interrupt signal!' sys.exit(0) def train(self, w1, w2, w3, m): ''' 传入三个wav文件,生成snowboy的.pmdl模型 ''' def get_wave(fname): with open(fname, 'rb') as infile: return base64.b64encode(infile.read()).decode('utf-8') url = 'https://snowboy.kitt.ai/api/v1/train/' data = { "name": "wukong-robot", "language": "zh", "token": config.get('snowboy_token', ''), "voice_samples": [{ "wave": get_wave(w1) }, { "wave": get_wave(w2) }, { "wave": get_wave(w3) }] } response = requests.post(url, json=data) print(response.ok) if response.ok: with open(m, "wb") as outfile: outfile.write(response.content) return 'Snowboy模型已保存至{}'.format(m) else: return "Snowboy模型生成失败,原因:{}".format(response.text)