def bing_callback(self, recognizer, audio): """ called from the background thread """ try: captured_audio = recognizer.recognize_bing(audio, key=self.key, language=self.language, show_all=self.show_all) Utils.print_info("Speech to Text Engine: Bing thinks you said %s" % captured_audio) self._analyse_audio(captured_audio) except sr.UnknownValueError: Utils.print_warning( "Speech to Text Engine: Bing could not understand audio") # callback anyway, we need to listen again for a new order self._analyse_audio(audio_to_text=None) except sr.RequestError as e: Utils.print_danger( "Speech to Text Engine: could not request results from Bing; {0}" .format(e)) # callback anyway, we need to listen again for a new order self._analyse_audio(audio_to_text=None) except AssertionError: Utils.print_warning( "Speech to Text Engine: no audio caught from microphone") self._analyse_audio(audio_to_text=None)
def wit_callback(self, recognizer, audio): try: captured_audio = recognizer.recognize_wit(audio, key=self.key, show_all=self.show_all) Utils.print_info( "Speech to Text Engine: Wit.ai thinks you said %s" % captured_audio) self._analyse_audio(captured_audio) except sr.UnknownValueError: Utils.print_warning( "Speech to Text Engine: Wit.ai could not understand audio") # callback anyway, we need to listen again for a new order self._analyse_audio(audio_to_text=None) except sr.RequestError as e: Utils.print_danger( "Speech to Text Engine: could not request results from Wit.ai; {0}" .format(e)) # callback anyway, we need to listen again for a new order self._analyse_audio(audio_to_text=None) except AssertionError: Utils.print_warning( "Speech to Text Engine: no audio caught from microphone") self._analyse_audio(audio_to_text=None)
def apiai_callback(self, recognizer, audio): """ called from the background thread :param recognizer: :param audio: :return: """ try: captured_audio = recognizer.recognize_api(audio, client_access_token=self.key, language=self.language, session_id=self.session_id, show_all=self.show_all) Utils.print_info("Speech to Text Engine: Api.ai thinks you said %s" % captured_audio) self._analyse_audio(captured_audio) except sr.UnknownValueError as e: Utils.print_warning("Speech to Text Engine: Api.ai could not understand audio; {0}".format(e)) # callback anyway, we need to listen again for a new order self._analyse_audio(audio_to_text=None) except sr.RequestError as e: Utils.print_danger("Speech to Text Engine: could not request results from Api.ai; {0}".format(e)) # callback anyway, we need to listen again for a new order self._analyse_audio(audio_to_text=None) except AssertionError: Utils.print_warning("Speech to Text Engine: no audio caught from microphone") self._analyse_audio(audio_to_text=None)
def sphinx_callback(self, recognizer, audio): """ called from the background thread """ try: captured_audio = recognizer.recognize_sphinx( audio, language=self.language, keyword_entries=self.keyword_entries, grammar=self.grammar_file) Utils.print_info( "Speech to Text Engine: CMU Sphinx thinks you said %s" % captured_audio) self._analyse_audio(captured_audio) except sr.UnknownValueError: Utils.print_warning( "Speech to Text Engine: CMU Sphinx could not understand audio") # callback anyway, we need to listen again for a new order self._analyse_audio(audio_to_text=None) except sr.RequestError as e: Utils.print_danger( "Speech to Text Engine: could not request results from CMU Sphinx; {0}" .format(e)) # callback anyway, we need to listen again for a new order self._analyse_audio(audio_to_text=None) except AssertionError: Utils.print_warning( "Speech to Text Engine: no audio caught from microphone") self._analyse_audio(audio_to_text=None)
def _check_dna_file(dna_file): """ Check the content of a DNA file :param dna_file: the dna to check :return: True if ok, False otherwise """ success_loading = True if "name" not in dna_file: Utils.print_danger("The DNA of does not contains a \"name\" tag") success_loading = False if "type" not in dna_file: Utils.print_danger("The DNA of does not contains a \"type\" tag") success_loading = False else: # we have a type, check that is a valid one if dna_file["type"] not in VALID_DNA_MODULE_TYPE: Utils.print_danger("The DNA type %s is not valid" % dna_file["type"]) Utils.print_danger("The DNA type must be one of the following: %s" % VALID_DNA_MODULE_TYPE) success_loading = False if "brain_supported_version" not in dna_file: Utils.print_danger("The DNA of does not contains a \"brain_supported_version\" tag") success_loading = False else: # brain_supported_version must be a non empty list if not isinstance(dna_file["brain_supported_version"], list): Utils.print_danger("brain_supported_version is not a list") success_loading = False else: if not dna_file["brain_supported_version"]: Utils.print_danger("brain_supported_version cannot be empty") success_loading = False else: for supported_version in dna_file["brain_supported_version"]: # check if major version is provided if not re.search('^[\d]*[.][\d]*$', str(supported_version)): Utils.print_danger("brain_supported_version cannot handle this format of version %s. " "Only major version should be provided" % supported_version) success_loading = False return success_loading
def main(): """Entry point of Brain.ai program.""" Utils.print_info("") Utils.print_info("Brain.ai (Version 0.1.4)") Utils.print_info("Copyright (C) 2018 by Alexander Paul P. Quinit") Utils.print_info("This program comes with ABSOLUTELY NO WARRANTY") Utils.print_info( "This is free software, and you are welcome to redistribute it under certain conditions" ) Utils.print_info("") # parse argument. the script name is removed try: parser = parse_args(sys.argv[1:]) except SystemExit: sys.exit(1) # check if we want debug configure_logging(debug=parser.debug) logger.debug("brain args: %s" % parser) # by default, no brain file is set. # Use the default one: brain.yml in the root path brain_file = None # check if user set a brain.yml file if parser.brain_file: brain_file = parser.brain_file # check the user provide a valid action if parser.action not in ACTION_LIST: Utils.print_warning("%s is not a recognised action\n" % parser.action) sys.exit(1) # install modules if parser.action == "install": if not parser.git_url: Utils.print_danger("please specify the git url") sys.exit(1) else: parameters = {"git_url": parser.git_url} res_manager = ResourcesManager(**parameters) res_manager.install() return # uninstall modules if parser.action == "uninstall": if not parser.neuron_name \ and not parser.stt_name \ and not parser.tts_name \ and not parser.trigger_name \ and not parser.signal_name: Utils.print_danger("please specify a module name with " "--neuron-name " "or --stt-name " "or --tts-name " "or --trigger-name " "or --signal-name") sys.exit(1) else: res_manager = ResourcesManager() res_manager.uninstall(neuron_name=parser.neuron_name, stt_name=parser.stt_name, tts_name=parser.tts_name, trigger_name=parser.trigger_name, signal_name=parser.signal_name) return # load the brain once brain_loader = BrainLoader(file_path=brain_file) brain = brain_loader.brain # load settings # get global configuration once settings_loader = SettingLoader() settings = settings_loader.settings if parser.action == "start": # user set a synapse to start if parser.run_synapse is not None: SynapseLauncher.start_synapse_by_list_name([parser.run_synapse], brain=brain) if parser.run_order is not None: SynapseLauncher.run_matching_synapse_from_order(parser.run_order, brain=brain, settings=settings, is_api_call=False) if (parser.run_synapse is None) and (parser.run_order is None): # if --deaf if parser.deaf: settings.options.deaf = True # start rest api start_rest_api(settings, brain) start_brain(settings, brain)