static void Main(string[] argv) { if (argv.Length < 2) { Console.WriteLine("Usage:"); Console.WriteLine("\tUniRecog \"/path/to/grammar/file\" \"/path/to/input/file\""); Environment.Exit(1); } // Just detect various directory layout constellations if (!Directory.Exists(ROOT_DIR)) { ROOT_DIR = "../../../../UniMRCP"; } if (!Directory.Exists(ROOT_DIR)) { ROOT_DIR = "../../../../unimrcp"; } string grammarFile = argv[0].Trim(); string inputFile = argv[1].Trim(); ushort major, minor, patch; UniMRCPClient.WrapperVersion(out major, out minor, out patch); Console.WriteLine("This is a sample C# UniMRCP client recognizer scenario."); Console.WriteLine("Wrapper version: {0}.{1}.{2}", major, minor, patch); Console.WriteLine("Use client configuration from {0}/conf/unimrcpclient.xml", ROOT_DIR); Console.WriteLine("Use profile {0}", MRCP_PROFILE); Console.WriteLine("Use recognition grammar: `{0}'", grammarFile); Console.WriteLine("Use recognition input file: `{0}'", inputFile); Console.WriteLine(); Console.WriteLine("Press enter to start the session..."); Console.ReadKey(); UniRecogLogger logger = new UniRecogLogger(); try { // Initialize platform first UniMRCPClient.StaticInitialize(logger, UniMRCPLogPriority.INFO); } catch (ApplicationException ex) { Console.WriteLine("Unable to initialize platform: " + ex.Message); Environment.Exit(1); } UniMRCPClient client = null; UniRecogSession sess = null; UniRecogChannel chan = null; try { // Create and start client in a root dir client = new UniMRCPClient(ROOT_DIR, true); // Create a session using MRCP profile MRCP_PROFILE sess = new UniRecogSession(client, MRCP_PROFILE); // Create audio termination with capabilities UniRecogTermination term = new UniRecogTermination(sess, inputFile); term.AddCapability("LPCM", UniMRCPSampleRate.SAMPLE_RATE_8000); // Semaphore to wait for completion Semaphore sem = new Semaphore(0, 1); // Add signaling channel (and start processing in OnAdd method chan = new UniRecogChannel(sess, term, sem, grammarFile, inputFile); // Now wait until the processing finishes sem.WaitOne(); } catch (ApplicationException ex) { err = 1; Console.WriteLine("An error occured: " + ex.Message); } // Ensure correct destruction order (do not let GC decide) if (chan != null) { chan.Dispose(); } if (sess != null) { sess.Dispose(); } if (client != null) { client.Dispose(); } UniMRCPClient.StaticDeinitialize(); Console.WriteLine("Program finished, memory released. Press enter to exit."); Console.ReadKey(); Environment.Exit(err); }
static void Main(string[] argv) { if (argv.Length < 2) { Console.WriteLine("Usage:"); Console.WriteLine("\tUniRecog \"/path/to/grammar/file\" \"/path/to/input/file\""); Environment.Exit(1); } // Just detect various directory layout constellations if (!Directory.Exists(ROOT_DIR)) ROOT_DIR = "../../../../UniMRCP"; if (!Directory.Exists(ROOT_DIR)) ROOT_DIR = "../../../../unimrcp"; string grammarFile = argv[0].Trim(); string inputFile = argv[1].Trim(); ushort major, minor, patch; UniMRCPClient.WrapperVersion(out major, out minor, out patch); Console.WriteLine("This is a sample C# UniMRCP client recognizer scenario."); Console.WriteLine("Wrapper version: {0}.{1}.{2}", major, minor, patch); Console.WriteLine("Use client configuration from {0}/conf/unimrcpclient.xml", ROOT_DIR); Console.WriteLine("Use profile {0}", MRCP_PROFILE); Console.WriteLine("Use recognition grammar: `{0}'", grammarFile); Console.WriteLine("Use recognition input file: `{0}'", inputFile); Console.WriteLine(); Console.WriteLine("Press enter to start the session..."); Console.ReadKey(); UniRecogLogger logger = new UniRecogLogger(); try { // Initialize platform first UniMRCPClient.StaticInitialize(logger, UniMRCPLogPriority.INFO); } catch (ApplicationException ex) { Console.WriteLine("Unable to initialize platform: " + ex.Message); Environment.Exit(1); } UniMRCPClient client = null; UniRecogSession sess = null; UniRecogChannel chan = null; try { // Create and start client in a root dir client = new UniMRCPClient(ROOT_DIR, true); // Create a session using MRCP profile MRCP_PROFILE sess = new UniRecogSession(client, MRCP_PROFILE); // Create audio termination with capabilities UniRecogTermination term = new UniRecogTermination(sess, inputFile); term.AddCapability("LPCM", UniMRCPSampleRate.SAMPLE_RATE_8000); // Semaphore to wait for completion Semaphore sem = new Semaphore(0, 1); // Add signaling channel (and start processing in OnAdd method chan = new UniRecogChannel(sess, term, sem, grammarFile, inputFile); // Now wait until the processing finishes sem.WaitOne(); } catch (ApplicationException ex) { err = 1; Console.WriteLine("An error occured: " + ex.Message); } // Ensure correct destruction order (do not let GC decide) if (chan != null) chan.Dispose(); if (sess != null) sess.Dispose(); if (client != null) client.Dispose(); UniMRCPClient.StaticDeinitialize(); Console.WriteLine("Program finished, memory released. Press enter to exit."); Console.ReadKey(); Environment.Exit(err); }