def _in(ctx): if not flMac: tts = pyttsx3.init() while not ctx.finished.is_set(): s = get() _logger.debug("Saying: %s", s) # Pause Ear (listening) while talking. Mute TTS. # TODO: move this somewhere else put('speech_recognition', 'mute') if flMac: _msg = subprocess.Popen(['echo', s], stdout=subprocess.PIPE) _tts = subprocess.Popen(['say'], stdin=_msg.stdout) _msg.stdout.close() _tts.communicate() else: tts.say(s) tts.runAndWait() # Wait until speaking ends. # Continue ear (listening). Unmute TTS. # TODO: move this somewhere else put('speech_recognition', 'unmute')
def _in(): default_mind = 'boot' load_minds() set_mind(default_mind) logging.debug('"{}" is now listening. Say "Boot Mind!" to see if it can hear you.'.format(default_mind)) while not oa.core.finished.is_set(): text = get() logging.debug('Input: {}'.format(text)) mind = oa.core.mind if (text is None) or (text.strip() == ''): # Nothing to do. continue t = text.upper() # Check for a matching command. fn = mind.kws.get(t, None) if fn is not None: # There are two types of commands, stubs and command line text. # For stubs, call `perform()`. if isCallable(fn): call_function(fn) oa.last_command = t # For strings, call `sys_exec()`. elif isinstance(fn, str): sys_exec(fn) oa.last_command = t else: # Any unknown command raises an exception. raise Exception("Unable to process: {}".format(text)) yield text
def _in(): if not flMac: if os.system('which festival') != 0: tts = pyttsx3.init() else: engine = "festival" while not oa.core.finished.is_set(): s = get() logging.debug("Saying: %s", s) # Pause Ear (listening) while talking. Mute TTS. # TODO: move this somewhere else put('speech_recognition', 'mute') if flMac: _msg = subprocess.Popen(['echo', s], stdout=subprocess.PIPE) _tts = subprocess.Popen(['say'], stdin=_msg.stdout) _msg.stdout.close() _tts.communicate() elif engine == "festival": os.system('echo "{0}" | festival --tts'.format(s)) else: tts.say(s) tts.runAndWait() # Wait until speaking ends. # Continue ear (listening). Unmute TTS. # TODO: move this somewhere else put('speech_recognition', 'unmute')
def _in(): if not flMac: tts = pyttsx3.init() #voice = tts.getProperty('voices')[26] # the french voice #tts.setProperty('voice', 'french+f2') #tts.setProperty('rate', 120) #tts.runAndWait() while not oa.core.finished.is_set(): s = get() logging.debug("Saying: %s", s) # Pause Ear (listening) while talking. Mute TTS. # TODO: move this somewhere else put('speech_recognition', 'mute') if flMac: _msg = subprocess.Popen(['echo', s], stdout=subprocess.PIPE) _tts = subprocess.Popen(['say'], stdin=_msg.stdout) _msg.stdout.close() _tts.communicate() else: #tts.say(s) #tts.runAndWait() os.system("pico2wave -l fr-FR -w {}{} \"{}\"".format( TMP_FILE, ".wav", s.lower())) os.system("aplay -q {}{}".format(TMP_FILE, ".wav")) # Wait until speaking ends. # Continue ear (listening). Unmute TTS. # TODO: move this somewhere else put('speech_recognition', 'unmute')
def _in(): while not oa.core.finished.is_set(): path = get() # Pause listening while talking. Mute STT. put('speech_recognition', 'mute') try: playsound.playsound(path) except Exception as ex: logging.error("Error playing sound: {}".format(ex)) # Audio complete. Begin listening. Unmute STT. put('speech_recognition', 'unmute')
def _in(ctx): while not ctx.finished.is_set(): path = get() # Pause listening while talking. Mute STT. put('speech_recognition', 'mute') try: subprocess.call(f'aplay {path}', shell=True) except Exception as ex: _logger.error("Error playing sound: {}".format(ex)) # Audio complete. Begin listening. Unmute STT. put('speech_recognition', 'unmute')
def _in(): mute = 0 while not oa.core.finished.is_set(): raw_data = get() if isinstance(raw_data, str): if raw_data == 'mute': logging.debug('Muted') mute = 1 elif raw_data == 'unmute': logging.debug('Unmuted') mute = 0 time.sleep(.9) empty() continue # Mute mode. Do not listen until unmute. if mute: continue # Obtain audio data. try: dinf = get_decoder() decoder = dinf.decoder decoder.start_utt() # Begin utterance processing. # Process audio data with recognition enabled (no_search = False), as a full utterance (full_utt = True) decoder.process_raw(raw_data, False, False) decoder.end_utt() # Stop utterance processing. except Exception as e: logging.error(e) else: hypothesis = decoder.hyp() if hypothesis is not None: hyp = hypothesis.hypstr if (hyp is None) or (hyp.strip() == ''): continue logging.info("Heard: {}".format(hyp)) if hyp.upper() in dinf.phrases: yield hyp else: continue else: logging.warn('Speech not recognized')
def _in(): if not flMac: tts = pyttsx3.init() while not oa.core.finished.is_set(): s = get() # Pause Ear (listening) while talking. Mute TTS. # TODO: move this somewhere else put('speech_recognition', 'mute') if flMac: _msg = subprocess.Popen(['echo', s], stdout=subprocess.PIPE) _tts = subprocess.Popen(['say'], stdin=_msg.stdout) _msg.stdout.close() _tts.communicate() else: say.say(s) # tempDir = tempfile.gettempdir() # filename = genFilename(s, '.mp3') # filepath = os.path.join(tempDir, filename) # if not os.path.exists(filepath): # try: # tts = gTTS(s, 'en') # with open(filepath, 'wb') as f: # tts.write_to_fp(f) # print(f"Video Download: {filename}") # except: # raise Exception('Failed to Download Video') # else: # print("Video already in cache") # playsound(filepath) # print(f"Writing to {filepath}") # song = AudioSegment.from_file(filepath, format="mp3") # p.play() # play(song) #tts.say(s) #tts.runAndWait() # Wait until speaking ends. # Continue ear (listening). Unmute TTS. # TODO: move this somewhere else put('speech_recognition', 'unmute')