6 gi.require_version(
'Gst',
'1.0')
7 from gi.repository
import GObject, Gst
13 from hmi
import AbstractHMIServer, HMIResult
16 from .kaldi_gstreamer_app
import KaldiGstApp
21 Subclass of AbstractHMIServer that creates a HMI client for
26 Class constructor that initializes the parent AbstractHMIServer class
27 and gets parameters from ROS parameter server
29 super(HMIServerKaldiClient, self).
__init__(rospy.get_name())
37 kaldi_root = os.environ.get(
"KALDI_ROOT",
None)
38 if kaldi_root
is None:
39 raise Exception(
"Environment variable KALDI_ROOT is not set")
41 gst_plugin_path = os.environ.get(
"GST_PLUGIN_PATH",
None)
42 if gst_plugin_path
is None:
43 raise Exception(
"Environment variable GST_PLUGIN_PATH is not set")
45 kaldi_gst_plugin_path = os.path.join(kaldi_root,
"src/gst-plugin")
46 if kaldi_gst_plugin_path
not in gst_plugin_path:
47 raise Exception(
"Kaldi gst plugin path {} not in gst plugin path {}".format(kaldi_gst_plugin_path,
52 Method override to start speech recognition upon receiving a query
55 :param description: (str) description of the HMI request
56 :param grammar: (str) grammar that should be used
57 :param target: (str) target that should be obtained from the grammar
58 :param is_preempt_requested: (callable) checks whether a preempt is requested by the hmi client
63 bus.add_signal_watch()
66 while not self.
_kaldi_app.sentence
and not rospy.is_shutdown()
and not is_preempt_requested():
67 rospy.logdebug(
"No sentence received so far...")
71 rospy.loginfo(
"Kaldi returned: {}".format(self.
_kaldi_app.sentence))
73 rospy.logdebug(
"Sending stop event")
74 self.
_kaldi_app.pipeline.send_event(Gst.Event.new_eos())
75 return HMIResult(result_str,
"")
79 """ Callback for gstreamer pipeline bus message. Sets the gstreamer pipeline state to NULL and sets the
85 rospy.logdebug(
"Stopping gstreamer pipeline")
86 self.
_kaldi_app.pipeline.set_state(Gst.State.NULL)
87 rospy.logdebug(
"Setting kaldi app to None")
89 rospy.loginfo(
"Gstreamer pipeline stopped successfully")