I am using:
1) Visual C# 2010 (Windows Forms)
2) pocketsphinx_continuous.exe (Sending line commands trought cmd.exe console)
I want to share with you the simplest way (I think) you can bring "pocket sphinx" to live using C#. However this is not a complete functional code yet... Since: "output = e.Data" gets all the correct data ("INFO:" included), except it never gets the "READY....", the "Listening...", neither the "words" outputs (still, we can see them all in the "cmd.exe" console).
HELP: How can I get the FULL console output? (So I could parse the output)
NOTE: Odd... But I´ve noticed that, if I close the "cmd.exe" (console), before exiting my C# application... Then the "READY...." and the "Listening..." outputs are now pasted to my application as they should be before... BUT now that is too late (since closing the console, it closes "pocketsphinx_continuos.exe" too)... :(
/*----------------------------------------------------------------------PocketSphinxonC#-FullCodeSnippet@Copyrights:JorgeRosaEmail:jorge.bigarte@gmail.comWebsite:https://sites.google.com/site/jorgerosaportfolio1)Using"MS Windows 7"and"Microsoft Visual C# 2010 Express"2)I´vecreateda"Windows Form"(windowsapplication)witha"textBox"onit.3)Inthesamepathwheremy"myapp.exe"isrunning(inmycaseisin"(...)myapp/bin/Debug"folder,I´veacreatedafoldernamed"Sphinx"with"pocketsphinx_continuos.exe","pocketsphinx.dll","sphinxbase.dll","en-us.lm.dmp","cmudict-en-us.dict"andallrelatedfiles,insideit.----------------------------------------------------------------------*/usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Diagnostics;usingSystem.Threading;usingSystem.IO;namespacemyApp{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidForm1_Load(objectsender,EventArgse){/*StartSphinx:*/RunPocketSphinx();}privatevoidRunPocketSphinx(){stringcmd1="/c pushd "+Directory.GetCurrentDirectory()+"\\Sphinx";/*Pathto...*/stringcmd2="&pocketsphinx_continuous.exe -inmic yes -hmm Bunch -lm en-us.lm.dmp -dict cmudict-en-us.dict";/*SphinxCommands*/stringline=cmd1+cmd2;/*CreateProcess:*/Processp=newProcess();p.StartInfo.FileName="cmd.exe";p.StartInfo.UseShellExecute=false;p.StartInfo.RedirectStandardInput=true;p.StartInfo.RedirectStandardOutput=true;p.StartInfo.RedirectStandardError=true;p.StartInfo.CreateNoWindow=false;p.StartInfo.Arguments=line;/*OutputHandlers:*/p.EnableRaisingEvents=true;p.OutputDataReceived+=PocketSphinxHandler;p.ErrorDataReceived+=PocketSphinxHandler;/*StartProcess:*/p.Start();p.BeginOutputReadLine();p.BeginErrorReadLine();/*Exitprocessmustbedisabled,ofcourse:*//*p.WaitForExit();*/}privatevoidPocketSphinxHandler(objectsender,DataReceivedEventArgse){/*Gettheoutputfrom"cmd.exe"console:*/stringoutput=e.Data+Environment.NewLine;/*Parsingtheincomingdata:*/if(output.StartsWith("-")){output="";};/*Worksgreat!*/if(output.StartsWith("INFO:")){output="";};/*Worksgreat!*/if(output.StartsWith("READY....")){output="Sphinx is ready!...";};/*FAIL:Cantgetit...*/if(output.StartsWith("Listening...")){output="Sphinx is listening!...";};/*FAIL:Cantgetit...*//*Display"cmd.exe"outputinaTextBox:(Accessingtexboxfromanotherthread´s)*/textBox1.Invoke((MethodInvoker)delegate{try{textBox1.Text=output;}catch{}});/*Display"cmd.exe"outputinVisualC#Console:*/Console.WriteLine(output);}}}
ATTACHEMENT: The folders and files structure in a ".jpg" image. (As it is in my case, but could be helpful to start)
Hello all,
I am using:
1) Visual C# 2010 (Windows Forms)
2) pocketsphinx_continuous.exe (Sending line commands trought cmd.exe console)
I want to share with you the simplest way (I think) you can bring "pocket sphinx" to live using C#. However this is not a complete functional code yet... Since: "output = e.Data" gets all the correct data ("INFO:" included), except it never gets the "READY....", the "Listening...", neither the "words" outputs (still, we can see them all in the "cmd.exe" console).
HELP: How can I get the FULL console output?
(So I could parse the output)
NOTE: Odd... But I´ve noticed that, if I close the "cmd.exe" (console), before exiting my C# application... Then the "READY...." and the "Listening..." outputs are now pasted to my application as they should be before... BUT now that is too late (since closing the console, it closes "pocketsphinx_continuos.exe" too)... :(
ATTACHEMENT: The folders and files structure in a ".jpg" image.
(As it is in my case, but could be helpful to start)
Last edit: Jorge Rosa 2015-08-18
Help, please.
You need to use pocketsphinx library through interop framework instead of parsing stdout of pocketsphinx_continuous.