def retrieve_scores(word): filename = word + '.wav' grammarname = word + '-align.jsgf' model_path = get_model_path() # Initialize the config values config = DefaultConfig() config.set_boolean('-verbose', False) config.set_string('-hmm', os.path.join(model_path, 'en-us')) config.set_boolean('-lm', False) config.set_string('-dict', 'phonemes.dict.txt') config.set_boolean('-backtrace', True) config.set_boolean('-bestpath', False) config.set_boolean('-fsgusefiller', False) decoder = Decoder(config) # Set the search to JSGF Grammar jsgf = Jsgf(grammarname) rule = jsgf.get_rule('forcing.' + word) decoder.set_jsgf_file('grammar', grammarname) decoder.set_search('grammar') stream = open(filename, 'rb') utt_started = False scores = [] decoder.start_utt() while True: buf = stream.read(1024) if buf: decoder.process_raw(buf, False, False) in_speech = decoder.get_in_speech() if (in_speech and not utt_started): utt_started = True if (not in_speech and utt_started): decoder.end_utt() hyp = decoder.hyp() if hyp is not None: print('hyp: %s' % (hyp.best_score)) print_segments(decoder) scores = retrieve_segments(decoder) decoder.start_utt() utt_started = False else: break decoder.end_utt() print('scores:', scores) return scores
def get_config(self): # Create a decoder with a certain model config = DefaultConfig() #config.set_string('-hmm', os.path.join(self.model_path, 'en-us')) config.set_string('-hmm', os.path.join(Audio_Tuner.tuned_path, 'en-us-adapt')) config.set_string('-lm', os.path.join(Audio_Tuner.tuned_path, 'en-us.lm.bin')) #print("Using custom lm") #config.set_string('-lm', "/tmp/knowledge_base.lm") # To do this, just only copy the words you want over to another file config.set_string('-dict', self.dict_path) #print("using custom dict") #config.set_string('-dict', "/tmp/dict.dict") #config.set_string('-dict', os.path.join(self.model_path, # 'cmudict-en-us.dict')) config.set_string('-kws', self.keywords_path) config.set_string("-logfn", '/dev/null') config.set_boolean("-verbose", False) return config
def test_config_set_boolean(self): config = DefaultConfig() config.set_boolean('-backtrace', True) self.assertEqual(config.get_boolean('-backtrace'), True)
def test_config_set_boolean(self): config = DefaultConfig() config.set_boolean('-backtrace', True) self.assertEqual(config.get_boolean('-backtrace'), True)