private static bool InitAsr(ILegacyLogger i_Logger, eAsrType i_eAsrType, out IASR o_Asr) { bool bRet = true; o_Asr = null; try { switch (i_eAsrType) { case eAsrType.lumenvox: // bRet = Init_Lumenvox(i_Logger, out o_Asr); break; case eAsrType.lumenvox2: // bRet = Init_Lumenvox2(i_Logger, out o_Asr); break; case eAsrType.vestec: i_Logger.Log(Level.Exception, "InitAsr: That ASR is not yet implemented"); break; default: i_Logger.Log(Level.Exception, "InitAsr: That ASR is not yet implemented"); break; } } catch (Exception exc) { bRet = false; i_Logger.Log(Level.Exception, "InitAsr caught exception: " + exc.ToString()); } return(bRet); }
static void Main(string[] args) { ILegacyLogger logger = null; bool bRes = true; string sAsr = "", sGramPath = "", sUttPath = ""; int iRes, iNumIt = 0, iPause = 0, iNumArgsExpected = 5, iAsrIdx = 0, iGramIdx = 1, iUttIdx = 2, iItIdx = 3, iPauseIdx = 4; eAsrType eAsr = eAsrType.unknown; try { for (int ii = 0; ii < args.Length; ii++) { Console.Error.WriteLine("Arg {0}: '{1}'", ii, args[ii].ToString()); } Thread.CurrentThread.Name = "asrtest"; logger = new LegacyLogger(); logger.Init("", "", Thread.CurrentThread.Name, "", "", "/opt/speechbridge/logs"); bRes = logger.Open(); if (!bRes || (args.Length != iNumArgsExpected)) { if (!bRes) { Console.Error.WriteLine("Unable to open the console logger!"); } else { logger.Log(Level.Warning, "Usage: asrtest AsrType GrammarFile UttWav NumIterations PauseInSecs"); logger.Log(Level.Warning, " AsrType can be: lumenvox, lumenvox2, OR vestec"); } return; } else { sAsr = args[iAsrIdx]; sGramPath = args[iGramIdx]; sUttPath = args[iUttIdx]; iNumIt = int.Parse(args[iItIdx]); iPause = int.Parse(args[iPauseIdx]); if ((sAsr == eAsrType.julius.ToString()) || (sAsr == eAsrType.loquendo.ToString()) || (sAsr == eAsrType.pocketsphinx.ToString())) { logger.Log(Level.Exception, "That AsrType is not yet supported."); } else if (sAsr == eAsrType.lumenvox.ToString()) { eAsr = eAsrType.lumenvox; } else if (sAsr == eAsrType.lumenvox2.ToString()) { eAsr = eAsrType.lumenvox2; } else if (sAsr == eAsrType.vestec.ToString()) { eAsr = eAsrType.vestec; } if (eAsr != eAsrType.unknown) { iRes = RunTestBuffer(logger, eAsr, sGramPath, sUttPath, iNumIt, iPause); logger.Log(Level.Info, "Successfully completed " + iRes.ToString() + " iterations."); } } logger.Close(); } catch (Exception exc) { logger.Log(Level.Exception, "Main caught exception: " + exc.ToString()); } return; }
private static int RunTestBuffer(ILegacyLogger i_Logger, eAsrType i_eAsrType, string i_sGramPath, string i_sUttPath, int i_iNumIt, int i_iPause) { StreamReader srGram = null; FileInfo fiUtt = null; FileStream fsUtt = null; byte[] abUtt = null; StringBuilder sbGram = null; string sTmp = "", sGram = ""; int ii = 0, iRead = 0, iLen = 0, iRem = 0, jj = 0; bool bRes = true; IASR oAsr = null; RecognitionResult[] aResults = null; try { // Load grammar file and utterance WAV into buffers sbGram = new StringBuilder(); srGram = new StreamReader(i_sGramPath, Encoding.UTF8); while ((sTmp = srGram.ReadLine()) != null) { sbGram.Append(sTmp + System.Environment.NewLine); } sGram = sbGram.ToString(); i_Logger.Log(Level.Info, "Grammar: " + sGram + ""); fiUtt = new FileInfo(i_sUttPath); fsUtt = fiUtt.OpenRead(); abUtt = new byte[fsUtt.Length]; iLen = iRem = (int)fsUtt.Length; do { iRead = fsUtt.Read(abUtt, 0, iRem); iRem -= iRead; } while (iRem > 0); // Do ASR init bRes = InitAsr(i_Logger, i_eAsrType, out oAsr); if (!bRes) { i_Logger.Log(Level.Exception, "InitAsr failed."); } else { // Run test for (ii = 0; ii < i_iNumIt; ii++) { bRes = oAsr.Open(); if (!bRes) { i_Logger.Log(Level.Exception, "Asr.Open failed."); } bRes = oAsr.ResetGrammar(); if (!bRes) { i_Logger.Log(Level.Exception, "Asr.ResetGrammar failed."); } bRes = oAsr.LoadGrammar(false, "main", sGram); if (!bRes) { i_Logger.Log(Level.Exception, "Asr.LoadGrammar failed."); bRes = oAsr.Close(); return(ii); } SendData(oAsr, abUtt, true); // Use streaming // SendData(oAsr, abUtt, false); // Doesn't stream bRes = oAsr.Results(out aResults); if (!bRes) { i_Logger.Log(Level.Exception, "Asr.Results failed."); } else { for (jj = 0; jj < aResults.Length; jj++) { i_Logger.Log(Level.Info, "Iteration #" + ii.ToString() + ", result #" + jj.ToString() + ", decoded '" + aResults[jj].Result + "' with confidence " + aResults[jj].Probability + "%."); } } // Pause between iterations if ((i_iNumIt > 0) && (i_iPause > 0)) { Thread.Sleep(i_iPause * 1000); } } // for } } catch (Exception exc) { i_Logger.Log(Level.Exception, "RunTestBuffer Iteration #" + ii + ", caught exception: " + exc.ToString()); } return(ii); } // RunTestBuffer