Get user input from Speech?
It does not look like in your situation e.Result.Text
represents something that you can enumerate: you are checking the words that start the text, not the text in its entirety. In cases like this, you should not use a switch
, and go for a chain of if
-then
-else
s instead:
var text = e.Result.Text;
if (text.StartsWith("test")) {
writeConsolas("What do you want me to test?", me);
} else if (text.StartsWith("change username")) {
writeConsolas("What do you want to be called?", me);
} else if (text.StartsWith("exit")) {
writeConsolas("Do you wish me to exit?", me);
} else if (text.StartsWith("call me")) {
// Here you have the whole text. Chop off the "call me" part,
// using Substring(), and do whatever you need to do with the rest of it
} else
...
How do you make c# ask for a confirmation?
I'll express my answer using the high-level algorithm, for clarity.
- Wait to receive "Call Mark"
- Speak "Are you sure?"
- If the answer is "yes", then call Mark.
In code:
if (speech = "CALL MARK) {
var string input = Api.DetectSpeech(Source.Microphone);
if (input = "YES") {
Phone.DialNumber(Contacts.Mark);
}
}
Partial voice recognition
This functionality is called "keyword spotting". Usually you can not perform keyword spotting with speech recognition engine, you need a specific spotting package. The key issue is that engine should compare two outcomes constantly - word is found and word is not found. Speech recognition only looks for the words which are in grammar and doesn't consider other sounds. Spotting just requires a different algorithm.
There is a workaround to add many possible syllables or other sounds into speech recognition grammar and hope that engine will find them instead of keyword, but it's not a very good solution in terms of accuracy compared to specific keyword spotter.
If you are not closely tied to Microsoft's engine and you need a common language like US English or French you can implement keyword spotting with open source software toolkits for speech recognition like CMUSphinx.
Related Topics
Why Are Some Members Missing When Trying to Print an Object by Serializing to JSON
Static Property Using Inotifypropertychanged. C#
C# Generic Type Inference with Multiple Types
What Is the Command to Exit a Console Application in C#
Automatically Start a Windows Service on Install
C# - How to Iterate Through Classes Fields and Set Properties
How to Move Rigidbody Gameobject
Argumentoutofrangeexception on Initialized List
Complex Models and Partial Views - Model Binding Issue in ASP.NET MVC 3
When Should I Create a New Dbcontext()
Deserialize Specific Enum into System.Enum in JSON.Net
The Notorious Yet Unaswered Issue of Downloading a File When Windows Security Is Required
Starting and Stopping Iis Express Programmatically
How to Translate Cultureinfo Language Names
Why How to Not Edit a Method That Contains an Anonymous Method in the Debugger
Providing Input/Subcommands to a Command (Cli) Executed with Ssh.Net Sshclient.Runcommand