Hello,<div><br></div><div>I am trying to use CMU's PocketSphinx plugin for Gstreamer from Vala and I am running into a problem getting access to the message structure in my bus callback function (app_message). For some reason when I use the get_structure method to return the structure of the message and then call a method on that structure such as get_name() or get_string(), I get a critical Gstreamer error :</div>
<div><br></div><div><div>(cmu:26958): GStreamer-CRITICAL **: gst_structure_get_string: assertion `structure != NULL' failed</div><div><br></div><div>I just can't figure out why my message structure would be null. Any ideas? Here is my code ...</div>
<div><br></div><div><div>using Gst;</div><div><br></div><div><br></div><div>class Sphinx : GLib.Object {</div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// experimenting with gstreamer pocketsphinx</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>private Gst.Pipeline pipeline;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>private Gst.Element vader;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>dynamic Gst.Element asr;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>private Gst.Bus bus;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>private Gst.Structure msg;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>private Gst.Structure my_struct;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>private Gst.Structure my_struct2;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>private Gst.Message message;</div><div><br></div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>private MainLoop loop; </div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>public Sphinx() {</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>string a = """pulsesrc device="alsa_input.usb-AKM_AK5370-00-AK5370.analog-mono" ! audioconvert !""";</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>string b = """ audioresample ! vader name=vad auto-threshold=true ! pocketsphinx name=asr ! fakesink""";</div>
<div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>string pipeDef = a + b;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>try {</div><div>
<span class="Apple-tab-span" style="white-space:pre">                        </span>pipeline = (Pipeline)Gst.parse_launch(pipeDef);<span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>} catch (Error e) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>stdout.printf("Error: %s\n", e.message);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>bus = pipeline.get_bus();</div><div> bus.add_signal_watch();</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>bus.message.connect(app_message);</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>asr = pipeline.get_by_name("asr");</div><div>
<br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>asr.set_property("lm", "4038.lm");</div><div> asr.set_property("dict", "4038.dic");</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>asr.partial_result.connect(asrPartialResult);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>asr.result.connect(asrResult);</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>asr.set_property("configured", true);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>bus = pipeline.get_bus();</div>
<div> bus.add_signal_watch();</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>bus.message.connect(app_message);</div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>pipeline.set_state(Gst.State.PLAYING);</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>loop = new MainLoop ();</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>loop.run();</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>private void asrPartialResult(Gst.Element asr, string text, string uttid) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div>
<div> my_struct = new Gst.Structure.empty("partial_result");</div><div><br></div><div> my_struct.set_value("hyp", text);</div><div> my_struct.set_value("uttid", uttid);</div>
<div><br></div><div> asr.post_message(new Gst.Message.application(asr, my_struct));</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>private void asrResult(Gst.Element asr, string text, string uttid) {</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>//stdout.printf("%s", "inside asrResult");</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div> my_struct2 = new Gst.Structure.empty("result");</div><div><br></div><div> my_struct2.set_value("hyp", text);</div>
<div> my_struct2.set_value("uttid", uttid);</div><div><br></div><div> asr.post_message(new Gst.Message.application(asr, my_struct2));</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>private void app_message(Gst.Bus bus, Gst.Message p_msg) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>// trying to get the string that PocketSphinx converts my voice to here</div><div>
<span class="Apple-tab-span" style="white-space:pre">                </span>// but I keep getting : GStreamer-CRITICAL **: gst_structure_get_string: assertion `structure != NULL' failed</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>string msg_string = p_msg.get_structure().get_string("hyp");</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>/* // Not using any of this for now</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if (msgType == null) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>stdout.printf("%s", "null");<span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}else{</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>stdout.printf("%s", "not null");<span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>*/</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>//stdout.printf("%s", msgType);<span class="Apple-tab-span" style="white-space:pre">                </span></div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>//if (p_msg.type == MessageType.APPLICATION) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>//<span class="Apple-tab-span" style="white-space:pre">        </span>stdout.printf("%s", "booyah");</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>//}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>/*</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if (msg["hyp"]) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>stdout.printf("%s", "true");</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}else{</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>stdout.printf("%s", "false");</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>*/</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>/*</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>if (msgType == "partial_result") {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>//partialResult(msg["hyp"], msg["uttid"]);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}else if (msgType == "result") {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>//finalResult(msg["hyp"], msg["uttid"]);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>//pipeline.set_state(Gst.State.PAUSED);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>*/</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>//return true;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>private void partialResult(GLib.Value hyp, GLib.Value uttid) {</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>stdout.printf("%s", (string)hyp);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>private void finalResult(GLib.Value hyp, GLib.Value uttid) {</div><div>
<span class="Apple-tab-span" style="white-space:pre">                </span>stdout.printf("%s", (string)hyp);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><br></div><div>}</div>
<div><br></div><div><br></div><div>int main (string[] args) {</div><div> </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>Gst.init(ref args);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>var sphinx = new Sphinx();</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>return 0;</div><div>}</div><div><br></div><div><br></div><div><br></div><div><br></div></div>-- <br>Duff<br>
</div>