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)... :(
/*----------------------------------------------------------------------Pocket Sphinx on C# - Full Code Snippet@ Copyrights: Jorge RosaEmail: jorge.bigarte@gmail.comWebsite: https://sites.google.com/site/jorgerosaportfolio1) Using "MS Windows 7" and "Microsoft Visual C# 2010 Express" 2) I´ve created a "Windows Form" (windows application) with a "textBox" on it.3) In the same path where my "myapp.exe" is running (in my case is in "(...)myapp/bin/Debug" folder, I´ve a created a folder named "Sphinx" with "pocketsphinx_continuos.exe", "pocketsphinx.dll", "sphinxbase.dll", "en-us.lm.dmp", "cmudict-en-us.dict" and all related files, inside it.----------------------------------------------------------------------*/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){/* Start Sphinx: */RunPocketSphinx();}privatevoidRunPocketSphinx(){stringcmd1="/cpushd"+Directory.GetCurrentDirectory()+"\\Sphinx";/* Path to... */stringcmd2="&pocketsphinx_continuous.exe-inmicyes-hmmBunch-lmen-us.lm.dmp-dictcmudict-en-us.dict";/* Sphinx Commands */stringline=cmd1+cmd2;/* Create Process: */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;/* Output Handlers: */p.EnableRaisingEvents=true;p.OutputDataReceived+=PocketSphinxHandler;p.ErrorDataReceived+=PocketSphinxHandler;/* Start Process: */p.Start();p.BeginOutputReadLine();p.BeginErrorReadLine();/* Exit process must be disabled, of course: *//* p.WaitForExit(); */}privatevoidPocketSphinxHandler(objectsender,DataReceivedEventArgse){/* Get the output from "cmd.exe" console: */stringoutput=e.Data+Environment.NewLine;/* Parsing the incoming data: */if(output.StartsWith("-")){output="";};/* Works great! */if(output.StartsWith("INFO:")){output="";};/* Works great! */if(output.StartsWith("READY....")){output="Sphinxisready!...";};/* FAIL: Cant get it... */if(output.StartsWith("Listening...")){output="Sphinxislistening!...";};/* FAIL: Cant get it... *//* Display "cmd.exe" output in a TextBox: (Accessing texbox from another thread´s) */textBox1.Invoke((MethodInvoker)delegate{try{textBox1.Text=output;}catch{}});/* Display "cmd.exe" output in Visual C# 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.