Hello,<div><br></div><div>I am trying to use CMU&#39;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&#39; failed</div><div><br></div><div>I just can&#39;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 = &quot;&quot;&quot;pulsesrc device=&quot;alsa_input.usb-AKM_AK5370-00-AK5370.analog-mono&quot; ! audioconvert !&quot;&quot;&quot;;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>string b = &quot;&quot;&quot; audioresample ! vader name=vad auto-threshold=true ! pocketsphinx name=asr ! fakesink&quot;&quot;&quot;;</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(&quot;Error: %s\n&quot;, 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(&quot;asr&quot;);</div><div>
<br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>asr.set_property(&quot;lm&quot;, &quot;4038.lm&quot;);</div><div>                asr.set_property(&quot;dict&quot;, &quot;4038.dic&quot;);</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(&quot;configured&quot;, 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(&quot;partial_result&quot;);</div><div><br></div><div>              my_struct.set_value(&quot;hyp&quot;, text);</div><div>              my_struct.set_value(&quot;uttid&quot;, 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(&quot;%s&quot;, &quot;inside asrResult&quot;);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div>               my_struct2 = new Gst.Structure.empty(&quot;result&quot;);</div><div><br></div><div>               my_struct2.set_value(&quot;hyp&quot;, text);</div>
<div>               my_struct2.set_value(&quot;uttid&quot;, 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&#39; 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(&quot;hyp&quot;);</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(&quot;%s&quot;, &quot;null&quot;);<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(&quot;%s&quot;, &quot;not null&quot;);<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(&quot;%s&quot;, 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(&quot;%s&quot;, &quot;booyah&quot;);</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[&quot;hyp&quot;]) {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>stdout.printf(&quot;%s&quot;, &quot;true&quot;);</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(&quot;%s&quot;, &quot;false&quot;);</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 == &quot;partial_result&quot;) {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>//partialResult(msg[&quot;hyp&quot;], msg[&quot;uttid&quot;]);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>}else if (msgType == &quot;result&quot;) {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>//finalResult(msg[&quot;hyp&quot;], msg[&quot;uttid&quot;]);</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(&quot;%s&quot;, (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(&quot;%s&quot;, (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>