[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
---------- Forwarded message ----------
From: Brian Duffy <brd...@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...@gnome.org>,
clutter-app...@clutter-project.org
Hello all, I am trying to port
<http://goog_1501870203>this<http://cmusphinx.sourceforge.net/wiki/gstreamer>example
class Sphinx : GLib.Object {
public Sphinx() {
asr.partial_result.connect(asrPartialResult);
asr.result.connect(asrResult);
asr.set_property("configured", true);
pipeline.set_state(Gst.State.PLAYING);
}
asr.post_message(new Gst.Message.application(asr, my_struct));
}
asr.post_message(new Gst.Message.application(asr, my_struct));
}
stdout.printf("%s", (string)hyp);
}
}
int main (string[] args) {
Clutter.init(ref args);
Gst.init(ref args);
//ClutterGst.init(ref args);
Clutter.main();
--
Duff
> _______________________________________________
> vala-list mailing list
> vala...@gnome.org
> http://mail.gnome.org/mailman/listinfo/vala-list
_______________________________________________
vala-list mailing list
vala...@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list
> > Here are my compile warnings and code .... thanks. [brian@duffybr2foodie]$
--
Duff
I ran your code on my Fedora 16 box and I ran into a segfault but after
looking at the code and noticing a few things you did differently than me I
narrowed down the issue to the asr_partial_result and asr_result functions.
Specifically, the segfault was coming when trying to set the value for
"uttid" with gststruct.set_value("uttid", uttid);. I changed the parameter
type for uttid in the method definition to string instead of GLib.Value and
bingo it worked. Then I added my language model and dictionary to the code
in the init_gst method and PocketSphinx is now printing out my limited
language definition when I speak it! That was a huge help to me! Thanks a
lot. Are you the original author of the tutorial? It would be great if we
could add this Vala port to the article so that people can take advantage
of it easily. Do you have the contacts to get that done or should I try?
I'm attaching the code with my small changes, including 1)adding the
language model and dictionary 2)changing the parameter types for uttid and
3) my revised pipeline definition which shows how I got gstreamer to
recognize my usb microphone using the device keyword. If you have access to
edit the article then I think it is worth mentioning the lmtool
<http://www.speech.cs.cmu.edu/tools/lmtool-new.html>from CMU which
makes it really easy to define a language model and
dictionary and include them with your code.
Regards
Brian
On Thu, Mar 22, 2012 at 6:39 PM, JM <inter...@gmx.net> wrote:
> Hello Brian
> I tried porting that python example to vala (attached file) and it
> doesn't work here (Fails at runtime during asr.set_property("configured",
> true) ).
> Your version crashes at the same point here.
>
> I'm on ubuntu 11.10
>
> I tested the pipeline with
> gst-launch fakesrc ! audioconvert ! audioresample ! vader name=vad
> auto-threshold=true ! pocketsphinx name=asr ! fakesink
> and it fails with 'SIGSEGV accessing address 0x2c' as soon as it is
> (automatically)set to PAUSED.
> Funny thing is that the python example seems to work. Just had a look at
> the console. I didn't do further tests because my computer lacks a
> microphone.
> Your code looks fine, so far. On my machine I just don't get to the point
> where you have the issues.
> Regards