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 say(text): """ Text to speech using the `oa.audio.say` defined function. """ text = call_function(text) oa.sys.last_say = text # Put message into voice. put('voice', 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 command_loop(): from oa.modules.abilities.core import put while not a.finished.is_set(): cmd = input("OA> ") if cmd in ['q', 'quit']: a.finished.set() continue if cmd.find(' ') > -1: p, m = cmd.split(' ', 1) logging.debug("{} <- {}".format(p, m)) put(p, m)
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(): 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')
def play(fname): """ Play a sound file. """ put('sound', find_file(fname))