6 from __future__
import (absolute_import, division,
7 print_function, unicode_literals)
15 gi.require_version(
'Gst',
'1.0')
16 from gi.repository
import Gst
19 from .gstreamer_app
import GstApp
20 from .kaldi_grammar
import Grammar
23 """Kaldi Gstreamer Application"""
24 def __init__(self, model_path, grammar, target, ispreemt_requested):
25 """Initialize a KaldiGstApp object"""
28 self.
type =
'Kaldi-Gst-App'
32 subp_status = subprocess.call([
"mkdynamicgraph.bash",
36 self.
_error(
"mkdynamicgraph failed")
40 self.
asr = Gst.ElementFactory.make(
"onlinegmmdecodefaster",
"asr")
43 if not os.path.isdir(model_path):
44 self.
_error(
"Model (%s) not downloaded. Place the model at (%s) first" % model_path)
46 self.
asr.set_property(
"fst", model_path +
"HCLG.fst")
48 if os.path.exists(model_path +
"final.mat"):
49 self.
asr.set_property(
"lda-mat", model_path +
"final.mat")
51 self.
asr.set_property(
"model", model_path +
"final.mdl")
52 self.
asr.set_property(
"word-syms", model_path +
"words.txt")
53 self.
asr.set_property(
"silence-phones",
"1:2:3:4:5")
54 self.
asr.set_property(
"max-active", 4000)
55 self.
asr.set_property(
"beam", 12.0)
56 self.
asr.set_property(
"acoustic-scale", 0.0769)
58 print_msg =
"Couldn't create the onlinegmmfasterdecoder element.\n"
59 if "GST_PLUGIN_PATH" in os.environ:
60 print_msg +=
"Kaldi Gstreamer Plugin probably not compiled."
62 print_msg +=
"GST_PLUGIN_PATH unset.\nTry running: export GST_PLUGIN_PATH=$KALDI_ROOT/src/gst-plugin"
70 self.
pipeline.set_state(Gst.State.PLAYING)
83 self.
pub_str +=
" " + word.lower()