public override SpeechResult Process(InputStack command) { if (command.Count == 0) { return(null); } string c = command.Peek(); switch (c) { case "one": c = "1"; break; case "two": c = "2"; break; case "three": c = "3"; break; case "four": c = "4"; break; case "five": c = "5"; break; case "six": c = "6"; break; case "seven": c = "7"; break; case "eight": c = "8"; break; case "nine": c = "9"; break; case "zero": c = "0"; break; } if (int.TryParse(c, out int number)) { return(new SpeechResult(TokenType.Number, number, 0, 1)); } return(null); }
public override SpeechResult Process(InputStack command) { if (command.Count == 0) { return(null); } foreach (var alias in Aliases) { if (command.Peek().Equals(alias, StringComparison.OrdinalIgnoreCase)) { return(new SpeechResult(TokenType.Text, Word, 0, 1)); } } return(null); }
public List <SpeechResult> Process(string text) { var command = new InputStack(text); var resultList = new SpeechResultList(); while (command.Count > 0) { if (string.IsNullOrEmpty(command.Peek())) { command.Pop(); continue; } SortedSet <SpeechResult> results = new SortedSet <SpeechResult>(); foreach (var speechCommand in Commands) { var result = speechCommand.Process(command); if (result != null) { results.Add(result); } } if (results.Count > 0) { SpeechResult bestResult = results.First(); for (int i = 0; i < bestResult.TokenCount; i++) { command.Pop(); } resultList.Add(bestResult); } else { command.Pop(); } } resultList.Add(new SpeechResult(TokenType.Text, "Enter", 0, 0)); resultList.ForEach(x => x.SendCommand()); return(resultList); }