def __init__(self, recognizer): self.r = recognizer self.c = config self.speaker = Speaker() self.start_text = self.c.config['LOGS']['start_text'] self.listened_success_text = self.c.config['LOGS']['listened_success_text'] self.listened_error_text = self.c.config['LOGS']['listened_error_text'] self.speech_directory = self.c.config['CORE']['speech_directory'] self.beep_start = self.get_speeches_folder(self.c.config['CORE']['beep_start']) self.beep_end = self.get_speeches_folder(self.c.config['CORE']['beep_end'])
def __init__(self, recognizer): self.r = recognizer self.c = config self.speaker = Speaker() self.speech_directory = self.c.config['CORE']['speech_directory'] self.beep_start = self.get_speeches_folder( self.c.config['CORE']['beep_start']) self.beep_end = self.get_speeches_folder( self.c.config['CORE']['beep_end']) self.tts_option = self.c.config['TTS']['tts_player'].lower()
class AudioGetter: def __init__(self, recognizer): self.r = recognizer self.c = config self.speaker = Speaker() self.start_text = self.c.config['LOGS']['start_text'] self.listened_success_text = self.c.config['LOGS'][ 'listened_success_text'] self.listened_error_text = self.c.config['LOGS']['listened_error_text'] self.speech_directory = self.c.config['CORE']['speech_directory'] self.beep_start = self.get_speeches_folder( self.c.config['CORE']['beep_start']) self.beep_end = self.get_speeches_folder( self.c.config['CORE']['beep_end']) self.tts_option = self.c.config['TTS']['tts_player'].lower() def get_audio_from_inbuilt(self, source, signals=True): print(self.start_text) try: if signals: if self.tts_option == "os": self.speaker.speak_from_os(self.beep_start) elif self.tts_option == "mixer": self.speaker.speak_from_pygame(self.beep_start) else: raise AssertionError( "Fill in the tts_player option in config.ini file as either os or mixer." ) self.r.adjust_for_ambient_noise(source, duration=1) audio = self.r.listen(source) print(self.listened_success_text) if signals: if self.tts_option == "os": self.speaker.speak_from_os(self.beep_end) elif self.tts_option == "mixer": self.speaker.speak_from_pygame(self.beep_end) else: raise AssertionError( "Fill in the tts_player option in config.ini file as either os or mixer." ) return audio except AssertionError as e: print(e) print(self.listened_error_text) return False def listen(self, source, signals=True): try: self.get_audio_from_inbuilt(source, signals) except: raise Exception( "Make sure some kind of speaking device is properly installed in your system." ) def get_speeches_folder(self, filename): return os.path.abspath( os.path.join(os.path.dirname(__file__), os.pardir, self.speech_directory, filename))
class TextManager: def __init__(self): self.text_recognizer = TextRecognizer() self.speaker = Speaker() self.c = config def get_speech_from_text(self, text): option = self.c.config['TTS']['tts_engine'].lower() if option == "google": try: self.text_recognizer.recognize_from_google(text) except: print( "Some issue with google text to speech mechanism, change to some other service." " Or just wait for some time mate, turning off and on do magic sometimes too." ) return self else: raise Exception( "Man, did you mess up with tts_engine setting? Yes you did, don't lie to me" "Go check back the docs to see which options we offer, Sigh, tomorrow you'd" "be asking a porche out of internet.") def save_speech_result(self): try: return self.text_recognizer.save_speech_from_google() except: print( "Look it shouldn't happen but since it happened, just get to support tab of main website mate," " some issue with os is what I assume unless you haven't changed code if in that case" "man, well.") def speak_result(self, speech_result_filename): option = self.c.config['TTS']['tts_player'].lower() if option == "os": self.speaker.speak_from_os(speech_result_filename) else: raise Exception( "Man, did you mess up with tts_player setting? Yes you did, don't lie to me" "Go check back the docs to see which options we offer, Sigh, tomorrow you'd" "be asking a porche out of internet.") def speak(self, text): filename = self.get_speech_from_text(text).save_speech_result() self.speak_result(filename)
class TextManager: def __init__(self): self.text_recognizer = TextRecognizer() self.speaker = Speaker() self.c = config def get_speech_from_text(self, text): option = self.c.config['TTS']['tts_engine'].lower() if option == "google": try: self.text_recognizer.recognize_from_google(text) except: print("Some issue with google text to speech mechanism, change to some other service." " Or just wait for some time mate, turning off and on do magic sometimes too.") return self else: raise Exception("Man, did you mess up with tts_engine setting? Yes you did, don't lie to me" "Go check back the docs to see which options we offer, Sigh, tomorrow you'd" "be asking a porche out of internet.") def save_speech_result(self): try: return self.text_recognizer.save_speech_from_google() except: print("Look it shouldn't happen but since it happened, just get to support tab of main website mate," " some issue with os is what I assume unless you haven't changed code if in that case" "man, well.") def speak_result(self, speech_result_filename): option = self.c.config['TTS']['tts_player'].lower() if option == "os": self.speaker.speak_from_os(speech_result_filename) elif option == "mixer": self.speaker.speak_from_pygame(speech_result_filename) else: raise Exception("Man, did you mess up with tts_player setting?\n" "Yes you did, don't lie to me.\n" "Go check back the docs to see which options we offer. It's either os or mixer\n" "Sigh, tomorrow you'd be asking a porche out of internet.") def speak(self, text): filename = self.get_speech_from_text(text).save_speech_result() self.speak_result(filename)
class TextManager: def __init__(self): self.text_recognizer = TextRecognizer() self.speaker = Speaker() self.c = config def get_speech_from_text(self, text): option = self.c.config['TTS']['tts_engine'].lower() if option == "google": try: self.text_recognizer.recognize_from_google(text) except: print(_("error.google_text.unknown")) return self else: raise Exception( "Man, did you mess up with tts_engine setting? Yes you did, don't lie to me" "Go check back the docs to see which options we offer, Sigh, tomorrow you'd" "be asking a porche out of internet.") def save_speech_result(self): try: return self.text_recognizer.save_speech_from_google() except: print(_("error.google_text.save")) def speak_result(self, speech_result_filename): option = self.c.config['TTS']['tts_player'].lower() if option == "os": self.speaker.speak_from_os(speech_result_filename) elif option == "mixer": self.speaker.speak_from_pygame(speech_result_filename) else: raise Exception( "Man, did you mess up with tts_player setting?\n" "Yes you did, don't lie to me.\n" "Go check back the docs to see which options we offer. It's either os or mixer\n" "Sigh, tomorrow you'd be asking a porche out of internet.") def speak(self, text): filename = self.get_speech_from_text(text).save_speech_result() self.speak_result(filename)
def __init__(self): self.text_recognizer = TextRecognizer() self.speaker = Speaker() self.c = config