def disable_assistant(cls, **kwargs): """ - Clear console - Shutdown the assistant service """ cls.response('Bye') time.sleep(1) clear() logging.debug('Application terminated gracefully.') sys.exit()
def start_up(): """ Do initial checks, clear the console and print the assistant logo. """ startup_ckecks() clear() print(OutputStyler.CYAN + jarvis_logo + OutputStyler.ENDC) print(OutputStyler.HEADER + start_text + OutputStyler.ENDC) # Clear log file in each assistant fresh start with open(ROOT_LOG_CONF['handlers']['file']['filename'], 'r+') as f: f.truncate(0) logging.info('APPLICATION STARTED..')
def console_output(self, text=''): clear() # ------------------------------------------------------------------------------------------------------------- # Logo sector # ------------------------------------------------------------------------------------------------------------- stdout_print(jarvis_logo) stdout_print(" NOTE: CTRL + C If you want to Quit.") # ------------------------------------------------------------------------------------------------------------- # General info sector # ------------------------------------------------------------------------------------------------------------- settings_documents = db.get_documents(collection=MongoCollections.GENERAL_SETTINGS.value) if settings_documents: settings = settings_documents[0] print(OutputStyler.HEADER + console.add_dashes('GENERAL INFO') + OutputStyler.ENDC) enabled = OutputStyler.GREEN + 'ENABLED' + OutputStyler.ENDC if settings['response_in_speech'] else OutputStyler.WARNING + 'NOT ENABLED' + OutputStyler.ENDC print(OutputStyler.BOLD + 'RESPONSE IN SPEECH: ' + enabled) print(OutputStyler.BOLD + 'ENABLED PERIOD: ' + OutputStyler.GREEN + '{0}'.format(str(settings['enabled_period'])) + OutputStyler.ENDC + OutputStyler.ENDC) print(OutputStyler.BOLD + 'INPUT MODE: ' + OutputStyler.GREEN + '{0}'.format(settings['input_mode'].upper() + OutputStyler.ENDC) + OutputStyler.ENDC) # ------------------------------------------------------------------------------------------------------------- # System info sector # ------------------------------------------------------------------------------------------------------------- print(OutputStyler.HEADER + console.add_dashes('SYSTEM') + OutputStyler.ENDC) print(OutputStyler.BOLD + 'RAM USAGE: {0:.2f} GB'.format(self._get_memory()) + OutputStyler.ENDC) # ------------------------------------------------------------------------------------------------------------- # Assistant logs sector # ------------------------------------------------------------------------------------------------------------- print(OutputStyler.HEADER + console.add_dashes('LOG') + OutputStyler.ENDC) lines = subprocess.check_output(['tail', '-10', ROOT_LOG_CONF['handlers']['file']['filename']]).decode("utf-8") print(OutputStyler.BOLD + lines + OutputStyler.ENDC) # ------------------------------------------------------------------------------------------------------------- # Assistant input/output sector # ------------------------------------------------------------------------------------------------------------- print(OutputStyler.HEADER + console.add_dashes('ASSISTANT') + OutputStyler.ENDC) text = text if text else '' if text: print(OutputStyler.BOLD + '> ' + text + '\r' + OutputStyler.ENDC) print(OutputStyler.HEADER + console.add_dashes('-') + OutputStyler.ENDC)
def _set_microphone(self, pause_threshold, energy_threshold, ambient_duration, dynamic_energy_threshold): """ Setup the assistant microphone. """ microphone_list = self.sr.Microphone.list_microphone_names() clear() print("=" * 48) print("Microphone Setup") print("=" * 48) print("Which microphone do you want to use a assistant mic:") for index, name in enumerate(microphone_list): print("{0}) Microphone: {1}".format(index, name)) choices = "Choice[1-{0}]: ".format(len(microphone_list)) print( "WARNING: " "In case of error of 'Invalid number of channels' try again with different micrphone choice" ) index = input(choices) while not index.isnumeric(): index = input( "Please select a number between choices[1-{0}]: ".format( len(microphone_list))) with self.sr.Microphone(device_index=int(index), chunk_size=512) as source: self.speech_recognizer.pause_threshold = pause_threshold self.speech_recognizer.energy_threshold = energy_threshold clear() print("-" * 48) print("Microphone Calibration") print("-" * 48) print("Please wait.. for {} seconds ".format(ambient_duration)) self.speech_recognizer.adjust_for_ambient_noise( source, duration=ambient_duration) self.speech_recognizer.dynamic_energy_threshold = dynamic_energy_threshold print("Microphone calibrated successfully!") return source