//@Override public void newResult(edu.cmu.sphinx.result.Result result) { return; }
//@Override public override void startSpotting() { allocate(); edu.cmu.sphinx.result.Result recognizedResult = recognizer.recognize(); string timedResult = recognizedResult.getTimedBestResult(false, true); // Break the result into tokens and extract all time info from it. // I guess there should be better implementations for this using the // tokens // used to generate this result in the first place. Guess that's why I // call this a simple Phrase Spotter StringTokenizer st = new StringTokenizer(timedResult); //System.out.println(timedResult); timedData = new List <TimedData>(); while (st.hasMoreTokens()) { string currentToken = st.nextToken(); // typically this token will be like word(startTime,endTime) string word = currentToken.Substring(0, currentToken.IndexOf("(")); string timedPart = currentToken.Substring( currentToken.IndexOf("(") + 1, currentToken.IndexOf(")")); string startTime = timedPart.Substring(0, timedPart.IndexOf(",")); string endTime = timedPart.Substring(timedPart.IndexOf(",") + 1); if (word.CompareTo("<unk>") != 0) { timedData.Add(new TimedData(word, float.Parse(startTime), float.Parse(endTime))); } } // Now since we have eliminated <unk> from the result in TimedData // the list should look like Phrase - Phrase - Phrase .... // If this is not the case, raise error. /*Iterator<TimedData> resultIter = timedData.iterator(); * while (resultIter.hasNext()) {*/ foreach (var data in timedData) { bool startOfPhrase = true; float startTime = 0; float endTime = 0; /*Iterator<string> phraseIter = phrase.iterator(); * while (phraseIter.hasNext()) {*/ foreach (var word in phrase) { //string word = phraseIter.next(); /*if (resultIter.hasNext()) {*/ //TimedData data = resultIter.next(); // if phrase is begining store the start time if (startOfPhrase) { startTime = data.getStartTime(); startOfPhrase = false; } //System.out.println(data.getText()); if (!(word.Equals(data.getText(), StringComparison.InvariantCultureIgnoreCase))) { grammar.getInitialNode().dumpDot("./PSGraph.dot"); throw new Exception("Words in result don't match phrase (" + word + "," + data.getText() + ")"); } endTime = data.getEndTime(); // we're necessarily above /*} else { * grammar.getInitialNode().dumpDot("./PSGraph.dot"); * throw new Exception( * "The recognizer for phrase spotting didn't exit gracefully."); * }*/ } result.Add(new PhraseSpotterResult(phraseText, startTime, endTime)); } }