def task(quit_event): mic = Microphone(quit_event=quit_event) while not quit_event.is_set(): if mic.wakeup('respeaker'): print('Wake up') data = mic.listen() text = mic.recognize(data) if text: print('Recognized %s' % text)
def main(quit_event=None, lan='zh'): mic = Microphone(quit_event=quit_event, language=lan) from broker import ControllerBroker localBroker = ControllerBroker() localBroker.client.loop_start() alexa = Alexa(mic) alexa.get_token() os.system('aplay {}/hello.wav'.format(resources_path)) logging.debug('start') while not quit_event.is_set(): keyword = mic.wakeup(keywords=['ALEXA', 'GREEBLE']) logging.debug('Recognized %s' % keyword) if keyword and ('HELLO' in keyword and 'ALEXA' in keyword): logging.debug('wakeup Alexa') os.system('aplay {}/alexayes.wav'.format(resources_path)) data = mic.listen() try: alexa.recognize(data) except Exception as e: logging.warn(e.message) elif keyword and ('HELLO' in keyword and 'GREEBLE' in keyword): logging.debug('wakeup Zhima') os.system('aplay {}/alexayes.wav'.format(resources_path)) data = mic.listen() keyword = mic.recognize(data) #keyword = mic.detect() logging.debug('Get commands %s' % keyword) if keyword and localcommands(keyword, localBroker) == 0: os.system('aplay {}/alexaok.wav'.format(resources_path)) else: os.system('aplay {}/error.wav'.format(resources_path)) mic.close() localBroker.client.loop_stop() logging.debug('Mission completed')
def main(): global mic, quit_event bing = BingVoice(BING_KEY) awake = False pa = pyaudio.PyAudio() mic = Microphone(pa) player = Player(pa) while not quit_event.is_set(): if not awake: if mic.recognize(keyword='hey respeaker'): awake = True player.play(hi) continue else: break data = b''.join(mic.listen()) if data: # recognize speech using Microsoft Bing Voice Recognition try: text = bing.recognize(data, language='en-US') print('Bing:' + text.encode('utf-8')) tts_data = bing.synthesize('you said ' + text) player.play_raw(tts_data) if text.find('start recording') >= 0: mic.record('record.wav') elif text.find('stop recording') >= 0: mic.interrupt(stop_recording=True) elif text.find('play recording audio') >= 0: player.play('record.wav') except UnknownValueError: print( "Microsoft Bing Voice Recognition could not understand audio" ) except RequestError as e: print( "Could not request results from Microsoft Bing Voice Recognition service; {0}" .format(e)) else: print('no data') awake = False mic.close()
def main(): global mic, quit_event bing = BingVoice(BING_KEY) awake = False pa = pyaudio.PyAudio() mic = Microphone(pa) player = Player(pa) while not quit_event.is_set(): if not awake: if mic.recognize(keyword='hey respeaker'): awake = True player.play(hi) continue else: break data = b''.join(mic.listen()) if data: # recognize speech using Microsoft Bing Voice Recognition try: text = bing.recognize(data, language='en-US') print('Bing:' + text.encode('utf-8')) tts_data = bing.synthesize('you said ' + text) player.play_raw(tts_data) if text.find('start recording') >= 0: mic.record('record.wav') elif text.find('stop recording') >= 0: mic.interrupt(stop_recording=True) elif text.find('play recording audio') >= 0: player.play('record.wav') except UnknownValueError: print("Microsoft Bing Voice Recognition could not understand audio") except RequestError as e: print("Could not request results from Microsoft Bing Voice Recognition service; {0}".format(e)) else: print('no data') awake = False mic.close()
pa.terminate() signal.signal(signal.SIGINT, handle_int) worker.start() while not mission_completed: if not awake: if mic.detect(): awake = True player.play(hi) continue data = mic.listen() if not data: awake = False continue # recognize speech using Microsoft Bing Voice Recognition try: text = recognizer.recognize(data, language='en-US') print('Bing:' + text.encode('utf-8')) worker.push_cmd(text) worker.wait_done() if text.find('bye bye') > -1: awake = False elif text.find('shut down') > -1: handle_int(0,0)
print('quit') mission_completed = True mic.interrupt(stop_listening=True, stop_recording=True) signal.signal(signal.SIGINT, handle_int) while not mission_completed: if not awake: if mic.recognize(keyword='hey respeaker'): spi.write('wakeup\n') awake = True player.play(hi) continue data = b''.join(mic.listen()) if not data: break spi.write('wait\n') # recognize speech using Microsoft Bing Voice Recognition try: text = bing.recognize(data, language='en-US') spi.write('answer\n') print('Bing:' + text.encode('utf-8')) tts_data = bing.synthesize('you said ' + text) player.play_raw(tts_data) except UnknownValueError: print("Microsoft Bing Voice Recognition could not understand audio") except RequestError as e:
global mission_completed mission_completed = True mic.close() signal.signal(signal.SIGINT, handle_int) while not mission_completed: if not awake: if mic.detect(): spi.write('wakeup\n') awake = True player.play(hi) continue data = mic.listen() spi.write('wait\n') # recognize speech using Microsoft Bing Voice Recognition try: text = bing.recognize(data, language='en-US') spi.write('answer\n') print('Bing:' + text.encode('utf-8')) if re.search(r'start', text): spi.write('irlearning\n') player.play(startlearning) elif re.search(r'stop', text): spi.write('stoplearning\n') player.play(stoplearning)