I have just started trying out the Windows Speech to Text capabilities in C# .Net. I currently have the basics working (IE - Say something, and it will provide output based on what you say). However, I am struggling to figure out how to actually recieve user input as a variable.
What I mean by this, is that for example. If the user says:
"Call me John"
Then I want to be able to take the word John
as a variable and then store that as say, the persons username.
My current SpeechRecognized
event is as follows:
void zeusSpeechRecognised(object sender, SpeechRecognizedEventArgs e)
{
writeConsolas(e.Result.Text, username);
switch (e.Result.Grammar.RuleName)
{
case "settingsRules":
switch (e.Result.Text)
{
case "test":
writeConsolas("What do you want me to test?", me);
break;
case "change username":
writeConsolas("What do you want to be called?", me);
break;
case "exit":
writeConsolas("Do you wish me to exit?", me);
break;
}
break;
}
}
NB:writeConsolas
is just a glorified append line to a RichTextBox
.
I would like to add another case
which does the following:
case "call me"
username = e.Result.GetWordFollowingCallMe() //Obv not a method, but thats the general idea.
break;
Obviously, there is no such method, but that is the general idea that I wish to implement. Is there a way to search for specific phrases (IE: Call me
) and take the following word?
EDIT: I should note, that the e.Result.Text only returns words that it can match to Text in the dictionary.
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 aswitch
, and go for a chain ofif
-then
-else
s instead:I would look at updating your grammar to use SemanticValues so that you can extract the results directly rather than having to parse through recognition results. There's a quick example here that demonstrates
SemanticValues
,SemanticResultKeys
, andSemanticResultValues
.Well it can't be used in a
switch
one.Result.Text
, as it will test on the entire value :Call Me John
.You should have a condition in a
default
case, or outside of yourswitch
But I would really refactor all that, trying to avoid
switch
or massiveif..else if...else