def __init__(self, audio_file=None): """ Thread used to process n audio file and pass it to a callback method """ super(SpeechRecognition, self).__init__() self.callback = None self.audio_stream = None # get global configuration sl = SettingLoader() self.settings = sl.settings self.recognizer = SpeechRecognizer.ResponsiveRecognizer( multiplier=self.settings.options.recognizer_multiplier, energy_ratio=self.settings.options.recognizer_energy_ratio, recording_timeout=self.settings.options. recognizer_recording_timeout, recording_timeout_with_silence=self.settings.options. recognizer_recording_timeout_with_silence) if audio_file is None: # audio file not set, we need to capture a sample from the microphone self.microphone = SpeechRecognizer.MutableMicrophone() else: # audio file provided with sr.AudioFile(audio_file) as source: self.audio_stream = self.recognizer.record( source) # read the entire audio file
def __init__(self, audio_file=None): """ Thread used to caught n audio from the microphone and pass it to a callback method """ super(SpeechRecognition, self).__init__() self.recognizer = sr.Recognizer() self.microphone = sr.Microphone() self.callback = None self.stop_thread = None self.kill_yourself = False self.audio_stream = None # get global configuration sl = SettingLoader() self.settings = sl.settings if audio_file is None: # audio file not set, we need to capture a sample from the microphone with self.microphone as source: # we only need to calibrate once, before we start listening self.recognizer.adjust_for_ambient_noise(source) else: # audio file provided with sr.AudioFile(audio_file) as source: self.audio_stream = self.recognizer.record( source) # read the entire audio file
def setUp(self): # kill singleton Singleton._instances = dict() self.expected_result = "hello, this is a replaced word" # this allow us to run the test from an IDE and from the root with python -m unittest tests.TestNeuronModule self.file_template = get_test_path("templates/template_test.j2") self.say_template = "hello, this is a {{ test }}" self.message = {"test": "replaced word"} self.neuron_module_test = NeuronModule() self.file_settings = get_test_path("settings/settings_test.yml") self.settings = SettingLoader(file_path=self.file_settings).settings
def setUp(self): # get current script directory path. We are in /an/unknown/path/kalliope/core/tests cur_script_directory = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) # get parent dir. Now we are in /an/unknown/path/kalliope root_dir = os.path.normpath(cur_script_directory + os.sep + os.pardir) self.settings_file_to_test = root_dir + os.sep + "Tests/settings/settings_test.yml" # Init the folders, otherwise it raises an exceptions os.makedirs("/tmp/kalliope/tests/kalliope_resources_dir/neurons") os.makedirs("/tmp/kalliope/tests/kalliope_resources_dir/stt") os.makedirs("/tmp/kalliope/tests/kalliope_resources_dir/tts") os.makedirs("/tmp/kalliope/tests/kalliope_resources_dir/trigger") self.sl = SettingLoader(file_path=self.settings_file_to_test)
def __init__(self, audio_file=None): """ Thread used to caught n audio from the microphone and pass it to a callback method """ super(SpeechRecognition, self).__init__() self.recognizer = sr.Recognizer() self.microphone = sr.Microphone() self.callback = None self.stop_thread = None self.kill_yourself = False self.audio_stream = None # get global configuration sl = SettingLoader() self.settings = sl.settings if audio_file is None: # audio file not set, we need to capture a sample from the microphone with self.microphone as source: if self.settings.options.adjust_for_ambient_noise_second > 0: # threshold is calculated from capturing ambient sound logger.debug( "[SpeechRecognition] threshold calculated by " "capturing ambient noise during %s seconds" % self.settings.options.adjust_for_ambient_noise_second) Utils.print_info( "[SpeechRecognition] capturing ambient sound during %s seconds" % self.settings.options.adjust_for_ambient_noise_second) self.recognizer.adjust_for_ambient_noise( source, duration=self.settings.options. adjust_for_ambient_noise_second) else: # threshold is defined manually logger.debug( "[SpeechRecognition] threshold defined by settings: %s" % self.settings.options.energy_threshold) self.recognizer.energy_threshold = self.settings.options.energy_threshold Utils.print_info("[SpeechRecognition] Threshold set to: %s" % self.recognizer.energy_threshold) else: # audio file provided with sr.AudioFile(audio_file) as source: self.audio_stream = self.recognizer.record( source) # read the entire audio file
def __init__(self, audio_file=None): """ Thread used to caught n audio from the microphone and pass it to a callback method """ super(SpeechRecognition, self).__init__() self.recognizer = sr.Recognizer() self.microphone = sr.Microphone() self.callback = None self.audio_stream = None # get global configuration sl = SettingLoader() self.settings = sl.settings if self.audio_file_exist(OWN_AUDIO_FILE): # Maybe provided by the APP self.audio_file = OWN_AUDIO_FILE else: if self.load_status( ) == 'is_recording': # Record thread is still active while not self.record_is_finished(): time.sleep(0.1) else: SR = SpeechRecorder() SR.start() while not self.record_is_finished(): time.sleep(0.1) if self.audio_file_exist( HOTWORD_FILE ): # If there is a hotword_file, then merge both togther self.merge_audio() if self.audio_file: with sr.AudioFile(self.audio_file) as source: self.audio_stream = self.recognizer.record(source) os.remove( self.audio_file ) # we need to remove it, otherwise it would end in a loop if self.audio_file_exist(HOTWORD_FILE): os.remove(HOTWORD_FILE)
def __init__(self): threading.Thread.__init__(self) sl = SettingLoader() self.settings = sl.settings # To set the multiplier and energy_ratio in settings.yml, it need to be set in models/settings etc.