diff --git a/.options.txt b/.options.txt index 9977e71a69edff0e4f0cd104fee039d073f6bd1c..e3f3b2194dbeb3eba82a00865807fb613afdf763 100644 --- a/.options.txt +++ b/.options.txt @@ -1,5 +1,5 @@ -slu: 0 -xml_filename: /home/favre/work/kaldi/interface-rocio/data/simple-example.xml +asr_model: asr/custom.cfg osc_host: 127.0.0.1 +xml_filename: /home/favre/work/kaldi/interface-rocio/data/homeostasis_25nov.xml osc_port: 1234 -asr_model: asr/custom.cfg +slu: 0 diff --git a/asr.py b/asr.py index 9558fb44b283f7671c0a3ef829c351d1db6b0965..7019d1eee80cd0602a4f3f9270818d1b674d6b89 100644 --- a/asr.py +++ b/asr.py @@ -65,7 +65,7 @@ class ASR(Gtk.HBox): if self.asr: import config for name, value in config.read(asr_config_file).items(): - if name != 'dir' and name != 'name': + if name != 'dir' and name != 'name' and not name.startswith('slu') and not name.startswith('xml'): self.asr.set_property(name, value) else: print >> sys.stderr, "Couldn't create the kaldinnet2onlinedecoder element. " diff --git a/asr/custom.cfg b/asr/custom.cfg new file mode 100644 index 0000000000000000000000000000000000000000..f4fafd3f27a8b1df13b925659c24164930242953 --- /dev/null +++ b/asr/custom.cfg @@ -0,0 +1,19 @@ +dir = tools/model +name = Custom (compiled from simple-example.xml) + +xml_filename = data/simple-example.xml +slu_prefix = $dir/automate/simple-example_%s +slu_actions = $dir/simple-example.action + +fst = $dir/HCLG.fst +model = $dir/final.mdl +word-syms = $dir/words.txt +feature-type = mfcc +mfcc-config = $dir/conf/mfcc.conf +ivector-extraction-config = $dir/conf/ivector_extractor.fixed.conf +max-active = 7000 +beam = 11.0 +lattice-beam = 6.0 +do-endpointing = True +endpoint-silence-phones = 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35 + diff --git a/main.py b/main.py index 3b9e217f65582402626490ce76ffd1cfae56ab80..52f8a9df9980d9ebfa9ca6f80e223ac8c8026939 100644 --- a/main.py +++ b/main.py @@ -28,9 +28,13 @@ import confirm, asr, actions, xmlview import levenstein, slu, osc class ScriptedASR(Gtk.Window): - def __init__(self, xml_filename, asr_config_file, osc_host, osc_port, slu_type): + def __init__(self, asr_config_file, osc_host, osc_port, slu_type): super(ScriptedASR, self).__init__() + import config + config_dict = config.read(asr_config_file) + xml_filename = config_dict['xml_filename'] + self.connect("destroy", self.quit) self.set_default_size(1024, 768) self.set_border_width(10) @@ -53,14 +57,19 @@ class ScriptedASR(Gtk.Window): # slu #prefix = 'slu/automate/homeostasis_25nov_%s' #library = 'slu/src.new/librocio_slu.so' - prefix = 'tools/model/automate/simple-example_%s' - library = 'tools/slu/src/librocio_slu.so' + #prefix = 'tools/model/automate/simple-example_%s' + #library = 'tools/slu/src/librocio_slu.so' + + slu_prefix = config_dict['slu_prefix'] + slu_actions = config_dict['slu_actions'] + slu_library = '%s/tools/slu/src/librocio_slu.so' % directory + self.slu = {} - for section_fst in glob.glob(prefix % 'section*.fst'): + for section_fst in glob.glob(slu_prefix % 'section*.fst'): found = re.search('section(\d+)\.fst$', section_fst) if found: section_id = int(found.group(1)) - self.slu[section_id - 1] = slu.SLU(prefix % 'dico_word.txt', prefix % 'dico_action.txt', section_fst, prefix % 'clean_tail.fst', 'slu/homeostasis_25nov.action', library=library) + self.slu[section_id - 1] = slu.SLU(slu_prefix % 'dico_word.txt', slu_prefix % 'dico_action.txt', section_fst, slu_prefix % 'clean_tail.fst', slu_actions, library=slu_library) if slu_type == 0: for keyword in self.xmlview.keywords: keyword.add_listener(self.set_slu_history) @@ -216,16 +225,9 @@ class ScriptedASR(Gtk.Window): if __name__ == '__main__': import selector - xml_filename = 'data/homeostasis_25nov.xml' - asr_config_file = 'asr/mika-fred-1.cfg' - asr_config_file = 'asr/mika-fred-2.cfg' - asr_config_file = 'asr/fisher-benoit-1.cfg' - if len(sys.argv) > 1: - xml_filename = sys.argv[1] - if len(sys.argv) > 2: - asr_config_file = sys.argv[2] - xml_filename, asr_config_file, osc_host, osc_port, slu_type = selector.ModelSelector(xml_filename, asr_config_file).run() - if xml_filename == None or asr_config_file == None or osc_host == None or osc_port == None or slu_type == None: + asr_config_file = 'asr/custom.cfg' + asr_config_file, osc_host, osc_port, slu_type = selector.ModelSelector(asr_config_file).run() + if asr_config_file == None or osc_host == None or osc_port == None or slu_type == None: sys.exit(0) - app = ScriptedASR(xml_filename, asr_config_file, osc_host, osc_port, slu_type) + app = ScriptedASR(asr_config_file, osc_host, osc_port, slu_type) Gtk.main() diff --git a/selector.py b/selector.py index 8cf50a9ac5701c4bcf972b4190de1453a1c667ec..408b79d44c3c82923c6de6a30bd03cfa8a31947e 100644 --- a/selector.py +++ b/selector.py @@ -3,9 +3,9 @@ import os, sys, glob, re import config class ModelSelector(Gtk.Dialog): - def __init__(self, xml_filename = '', asr_model = ''): + def __init__(self, asr_model = ''): super(ModelSelector, self).__init__() - self.options = {'xml_filename': xml_filename, 'asr_model': asr_model, 'osc_host': '127.0.0.1', 'osc_port': '1234', 'slu': 'Regular'} + self.options = {'asr_model': asr_model, 'osc_host': '127.0.0.1', 'osc_port': '1234', 'slu': 'Regular'} self.load_options() self.set_title('Configuration') @@ -14,18 +14,18 @@ class ModelSelector(Gtk.Dialog): self.add_button("OK", Gtk.ResponseType.OK) box = self.get_content_area() - xml_box = Gtk.HBox() - xml_box.pack_start(Gtk.Label('XML file:'), False, False, 5) - xml_entry = Gtk.Entry() - xml_entry.set_text(self.options['xml_filename']) - xml_entry.set_width_chars(len(self.options['xml_filename'])) - self.xml_entry = xml_entry - xml_box.pack_start(xml_entry, True, True, 5) - xml_button = Gtk.Button("Choose...") - xml_button.connect('clicked', self.show_filechooser) - xml_box.pack_start(xml_button, False, False, 5) + #xml_box = Gtk.HBox() + #xml_box.pack_start(Gtk.Label('XML file:'), False, False, 5) + #xml_entry = Gtk.Entry() + #xml_entry.set_text(self.options['xml_filename']) + #xml_entry.set_width_chars(len(self.options['xml_filename'])) + #self.xml_entry = xml_entry + #xml_box.pack_start(xml_entry, True, True, 5) + #xml_button = Gtk.Button("Choose...") + #xml_button.connect('clicked', self.show_filechooser) + #xml_box.pack_start(xml_button, False, False, 5) - box.pack_start(xml_box, False, False, 5) + #box.pack_start(xml_box, False, False, 5) model_box = Gtk.HBox() model_box.pack_start(Gtk.Label('ASR model:'), False, False, 5) @@ -70,7 +70,7 @@ class ModelSelector(Gtk.Dialog): box.pack_start(osc_box, False, False, 5) - self.xml_entry.set_activates_default(True) + #self.xml_entry.set_activates_default(True) okButton = self.get_widget_for_response(response_id=Gtk.ResponseType.OK) okButton.set_can_default(True) okButton.grab_default() @@ -132,11 +132,11 @@ class ModelSelector(Gtk.Dialog): if response != Gtk.ResponseType.OK: return None, None, None, None self.options['asr_model'] = self.models[self.model_chooser.get_active()] - self.options['xml_filename'] = self.xml_entry.get_text() + #self.options['xml_filename'] = self.xml_entry.get_text() self.options['osc_host'] = self.osc_host.get_text() self.options['osc_port'] = self.osc_port.get_text() self.options['slu'] = self.slu_chooser.get_active() self.save_options() self.destroy() - return self.options['xml_filename'], self.options['asr_model'], self.options['osc_host'], self.options['osc_port'], self.options['slu'] + return self.options['asr_model'], self.options['osc_host'], self.options['osc_port'], self.options['slu']