Skip to content
Snippets Groups Projects
Commit 494a0602 authored by Benoit Favre's avatar Benoit Favre
Browse files

add possibility to click lines of text to select them

parent 4cdc7e25
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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")
......
......@@ -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)
......
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment