[Vala] Fwd: Porting "Using PocketSphinx with GStreamer and python" to Vala



Sorry, forgot to mention that the segfault happens when I speak into the
microphone; so my pipeline and asr are working well enough to pick up
utterances from my microphone.



---------- Forwarded message ----------
From: Brian Duffy <brduffy gmail com>
Date: Wed, Mar 21, 2012 at 2:30 PM
Subject: Porting "Using PocketSphinx with GStreamer and python" to Vala
To: vala-list <vala-list gnome org>,
clutter-app-devel-list clutter-project org


Hello all, I am trying to port
<http://goog_1501870203>this<http://cmusphinx.sourceforge.net/wiki/gstreamer>example
"Using PocketSphinx with GStreamer and Python" to Vala. I have an
example compiling but I am getting some warnings that I don't understand
and a segmentation fault when running. Also, I am not sure what data types
I should be using for the "text" and "uttid" params in the asrResult ,
asrPartialResult, partialResult and finalResult methods. My environment is
Fedora 16. PocketSphinx .7, latest gstreamer that comes with Fedora 16. I
am using Clutter (1.8) for the main loop because my application UI will
ultimately be written in Clutter. Any help would be greatly appreciated.
Here are my compile warnings and code .... thanks. [brian duffybr2 foodie]$
valac -X -O2 -g --pkg clutter-1.0 --pkg gstreamer-0.10 --pkg
gstreamer-interfaces-0.10 --pkg clutter-gst-1.0 cmu.vala
cmu.vala:25.24-25.48: warning: unhandled error `GLib.Error' pipeline =
(Pipeline)Gst.parse_launch(pipeDef); ^^^^^^^^^^^^^^^^^^^^^^^^^
cmu.vala:11.2-11.26: warning: field `Sphinx.vader' never used private
Gst.Element vader; ^^^^^^^^^^^^^^^^^^^^^^^^^ cmu.vala:112.6-112.26:
warning: local variable `sphinx' declared but never used var sphinx = new
Sphinx(); ^^^^^^^^^^^^^^^^^^^^^ /home/brian/BitBucketRepos/foodie/cmu.vala:
In function ‘sphinx_asrPartialResult’:
/home/brian/BitBucketRepos/foodie/cmu.vala:51:2: warning: passing argument
1 of ‘gst_structure_set_value’ discards ‘const’ qualifier from pointer
target type [enabled by default]
/usr/include/gstreamer-0.10/gst/gststructure.h:117:25: note: expected
‘struct GstStructure *’ but argument is of type ‘const struct GstStructure
*’ /home/brian/BitBucketRepos/foodie/cmu.vala:52:2: warning: passing
argument 1 of ‘gst_structure_set_value’ discards ‘const’ qualifier from
pointer target type [enabled by default]
/usr/include/gstreamer-0.10/gst/gststructure.h:117:25: note: expected
‘struct GstStructure *’ but argument is of type ‘const struct GstStructure
*’ /home/brian/BitBucketRepos/foodie/cmu.vala:54:2: warning: passing
argument 1 of ‘_gst_structure_copy0’ discards ‘const’ qualifier from
pointer target type [enabled by default] cmu.vala.c:287:17: note: expected
‘gpointer’ but argument is of type ‘const struct GstStructure *’
/home/brian/BitBucketRepos/foodie/cmu.vala: In function ‘sphinx_asrResult’:
/home/brian/BitBucketRepos/foodie/cmu.vala:65:2: warning: passing argument
1 of ‘gst_structure_set_value’ discards ‘const’ qualifier from pointer
target type [enabled by default]
/usr/include/gstreamer-0.10/gst/gststructure.h:117:25: note: expected
‘struct GstStructure *’ but argument is of type ‘const struct GstStructure
*’ /home/brian/BitBucketRepos/foodie/cmu.vala:66:2: warning: passing
argument 1 of ‘gst_structure_set_value’ discards ‘const’ qualifier from
pointer target type [enabled by default]
/usr/include/gstreamer-0.10/gst/gststructure.h:117:25: note: expected
‘struct GstStructure *’ but argument is of type ‘const struct GstStructure
*’ /home/brian/BitBucketRepos/foodie/cmu.vala:68:2: warning: passing
argument 1 of ‘_gst_structure_copy0’ discards ‘const’ qualifier from
pointer target type [enabled by default] cmu.vala.c:287:17: note: expected
‘gpointer’ but argument is of type ‘const struct GstStructure *’
/home/brian/BitBucketRepos/foodie/cmu.vala: In function
‘sphinx_app_message’: /home/brian/BitBucketRepos/foodie/cmu.vala:77:2:
warning: passing argument 1 of ‘_gst_structure_copy0’ discards ‘const’
qualifier from pointer target type [enabled by default] cmu.vala.c:287:17:
note: expected ‘gpointer’ but argument is of type ‘const struct
GstStructure *’ cmu.vala.c: In function ‘_vala_main’:
/home/brian/BitBucketRepos/foodie/cmu.vala:107:15: warning: ignoring return
value of ‘clutter_init’, declared with attribute warn_unused_result
[-Wunused-result] Compilation succeeded - 3 warning(s)




[code]
using Clutter;
using ClutterGst;
using Gst;


class Sphinx : GLib.Object {


// experimenting with gstreamer pocketsphinx
private Gst.Pipeline pipeline;
 private Gst.Element vader;
dynamic Gst.Element asr;
private Gst.Bus bus;
 private Gst.Structure msg;
private Gst.Structure my_struct;

 public Sphinx() {


string a = """pulsesrc
device="alsa_input.usb-AKM_AK5370-00-AK5370.analog-mono" ! audioconvert
!""";
 string b = """ audioresample ! vader name=vad auto-threshold=true !
pocketsphinx name=asr ! fakesink""";


string pipeDef = a + b;
pipeline = (Pipeline)Gst.parse_launch(pipeDef);

asr = pipeline.get_by_name("asr");

asr.set_property("lm", "4038.lm");
        asr.set_property("dict", "4038.dic");

asr.partial_result.connect(asrPartialResult);
asr.result.connect(asrResult);

asr.set_property("configured", true);

bus = pipeline.get_bus();
        bus.add_signal_watch();
bus.message.connect(app_message);

pipeline.set_state(Gst.State.PLAYING);

}


private void asrPartialResult(Gst.Element asr, GLib.Value text, GLib.Value
uttid) {
         my_struct = new Gst.Structure.empty("partial_result");

        my_struct.set_value("hyp", text);
        my_struct.set_value("uttid", uttid);

        asr.post_message(new Gst.Message.application(asr, my_struct));
 }


private void asrResult(Gst.Element asr, GLib.Value text, GLib.Value uttid) {

stdout.printf("%s", "inside asrResult");
         my_struct = new Gst.Structure.empty("result");

        my_struct.set_value("hyp", text);
        my_struct.set_value("uttid", uttid);

        asr.post_message(new Gst.Message.application(asr, my_struct));
 }


private void app_message(Gst.Bus bus, Gst.Message p_msg) {

 //stdout.printf("%s", "inside app_message");
msg = p_msg.get_structure();
 string msgType = msg.get_name();

if (msgType == "partial_result") {
 partialResult(msg["hyp"], msg["uttid"]);
}else if (msgType == "result") {
 finalResult(msg["hyp"], msg["uttid"]);
pipeline.set_state(Gst.State.PAUSED);
 }
  }

private void partialResult(GLib.Value hyp, GLib.Value uttid) {

stdout.printf("%s", (string)hyp);
}

 private void finalResult(GLib.Value hyp, GLib.Value uttid) {
stdout.printf("%s", (string)hyp);
 }


}


int main (string[] args) {

Clutter.init(ref args);
 Gst.init(ref args);

//ClutterGst.init(ref args);

 var sphinx = new Sphinx();

Clutter.main();

return 0;
}
[/code]
-- 
Duff



-- 
Duff


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]