S&box Wiki

Revision Difference

Speech_Recognition#550368

<cat>Code.Input</cat> <title>Speech Recognition</title> The Speech Recognition API functionality is currently limited to two simple method calls. It may potentially be expanded in the future to support complex custom grammar trees. # Usage ## Generic Speech If you want to listen for any speech you can use the below method. *It should be noted that this method yields a low accuracy result, and isn't perfect. You should search the returned string for keywords.* ```csharp SpeechRecognition.Listen( ( output ) => Log.Info( output ) ); SpeechRecognition.Start( ( output ) => Log.Info( output.Text ) ); ``` ## SpeechRecognitionResult ⤶ SpeechRecognition passes the SpeechRecognitionResult type which has the following parameters.⤶ ```csharp⤶ /// <summary>⤶ /// From 0-1 how confident are we that this is the correct result?⤶ /// </summary>⤶ public float Confidence { get; set; }⤶ ⤶ /// <summary>⤶ /// The text result from speech recognition.⤶ /// </summary>⤶ public string Text { get; set; }⤶ ⤶ /// <summary>⤶ /// Did we successfully find a match?⤶ /// </summary>⤶ public bool Success { get; set; }```⤶ ## Phrases ⤶ ```csharp⤶ If you want the game to only match to certain words you can pass a list of choices that the game can use to match the users input to a string, Limiting the pool of results.⤶ ```csharp⤶ var choices = new string[] { "Jump", "Move Left", "Move Right" }; SpeechRecognition.Listen( ( output ) => Log.Info( output ), choices ); ``` SpeechRecognition.Start( ( output ) => Log.Info( output.Text ), choices ); ```⤶ Note that the list of choices can be any ```IEnumerable<string>``` type.⤶ ⤶ ##Example⤶ ```csharp⤶ void AskUser()⤶ {⤶ //we are only wanting the game to guess between these three values.⤶ var choices = new string[] {⤶ "yes",⤶ "no",⤶ "maybe"⤶ };⤶ Log.Info("do you like pie?");⤶ SpeechRecognition.Listen( ( output ) => CheckAnswer( output), choices );⤶ }⤶ ⤶ void CheckAnswer(SpeechRecognitionResult result)⤶ {⤶ //Only Prodceede if the game found a word match and has high confidence its correct⤶ if (result.Success && result.Confidence >= 0.7f) ⤶ {⤶ if (result.Text == "yes")⤶ {⤶ Log.Info("YAY!");⤶ }⤶ }⤶ ⤶ ⤶ } ```