From 494a06023560e81d75492c1bb9f8af82d5812345 Mon Sep 17 00:00:00 2001 From: Benoit Favre <benoit.favre@lif.univ-mrs.fr> Date: Fri, 23 Jan 2015 21:57:36 +0100 Subject: [PATCH] add possibility to click lines of text to select them --- README | 5 +++++ asr.py | 7 ++++--- main.py | 15 +++++++++++++-- xmlview_widgets.py | 19 +++++++++++++------ 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/README b/README index 40d068c..b2c3bf7 100644 --- a/README +++ b/README @@ -22,3 +22,8 @@ Todo: - use GtkSourceView to allow editing the xml file directly - model selection in config file - integrate new xml with actions + +add model from mika +/storage/raid1/homedirs/mickael.rouvier/raid2/kaldi_english/exp/nnet2_online/ +--acoustic-scale=.04166666666666666666 +--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/asr.py b/asr.py index 74cfd5f..0e64abe 100644 --- a/asr.py +++ b/asr.py @@ -36,7 +36,7 @@ class ASR(Gtk.HBox): self.partial_hyp_callback = partial_hyp_callback Thread(target=self.init_gst).start() - def init_gst(self): + def init_gst(self, model="model2"): """Initialize the speech components""" GObject.idle_add(self._started_loading_asr) @@ -54,9 +54,10 @@ class ASR(Gtk.HBox): if not os.path.isfile(model_file): print >> sys.stderr, "Models not downloaded? Run prepare-models.sh first!" sys.exit(1) - self.asr.set_property("fst", "asr/model2/HCLG.fst") + self.asr.set_property("fst", "asr/%s/HCLG.fst" % model) self.asr.set_property("model", "asr/final.mdl") - self.asr.set_property("word-syms", "asr/model2/words.txt") + self.asr.set_property("word-syms", "asr/%s/words.txt" % model) + #self.asr.set_property("acoustic-scale", 0.0416) self.asr.set_property("feature-type", "mfcc") self.asr.set_property("mfcc-config", "asr/conf/mfcc.conf") self.asr.set_property("ivector-extraction-config", "asr/conf/ivector_extractor.fixed.conf") diff --git a/main.py b/main.py index f58b963..36f71c7 100755 --- a/main.py +++ b/main.py @@ -65,9 +65,20 @@ class ScriptedASR(Gtk.Window): style_provider.load_from_data(open('data/style.css', 'rb').read()) Gtk.StyleContext.add_provider_for_screen( Gdk.Screen.get_default(), style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) + for line in self.lines: + line.set_click_handler(self.line_clicked) + + def line_clicked(self, widget, event): + if self.current_line >= 0: + self.lines[self.current_line].highlight(False) + for i, line in enumerate(self.lines): + if widget is line: + self.current_line = i + self.lines[self.current_line].highlight(True) + def hyp_changed(self, hyp): #hyp = ' '.join(hyp).replace('[noise]', ' ').split() - words = hyp[-1].strip().split() + words = hyp[-1].strip().replace('_', ' ').split() if self.current_line >= len(self.lines) - 1: print "FINISHED" return @@ -92,7 +103,7 @@ class ScriptedASR(Gtk.Window): if __name__ == '__main__': - xml_filename = 'data/homeostasis_sept2014.xml' + xml_filename = 'data/homeostasis_25nov.xml' if len(sys.argv) > 1: xml_filename = sys.argv[1] app = ScriptedASR(xml_filename) diff --git a/xmlview_widgets.py b/xmlview_widgets.py index e784b52..42f9522 100644 --- a/xmlview_widgets.py +++ b/xmlview_widgets.py @@ -38,19 +38,26 @@ class Sequence(Gtk.VBox): self.lines.append(Line(line)) self.pack_start(self.lines[-1], True, True, 5) -class Line(Gtk.Label): +class Line(Gtk.EventBox): def __init__(self, text): super(Line, self).__init__() self.text = text - self.set_text(' ' + text) - self.set_halign(Gtk.Align.START) - self.get_style_context().add_class('text-line') + self.label = Gtk.Label() + self.label.set_text(' ' + text) + self.label.set_halign(Gtk.Align.START) + self.label.get_style_context().add_class('text-line') + self.add(self.label) + def set_click_handler(self, handler): + self.connect('button-press-event', handler) + cursor = Gdk.Cursor(Gdk.CursorType.HAND1) + self.get_window().set_cursor(cursor) + def highlight(self, highlighted=True): if highlighted: - self.get_style_context().add_class('highlighted') + self.label.get_style_context().add_class('highlighted') else: - self.get_style_context().remove_class('highlighted') + self.label.get_style_context().remove_class('highlighted') class Word: def __init__(self, text, start, end): -- GitLab