Get user input from speech?

I just started testing Windows Speech to Text features in C # .Net. I am currently working on the basics (IE - Say something and it will provide output based on what you say). However, I'm struggling to figure out how to really get user input as a variable.

What I mean by this is, 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 save that, as they say, the 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 an illustrious line of adding to RichTextBox .

I would like to add another case that 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 this is a general idea that I want to implement. Is there a way to search for specific phrases (IE: Call me ) and take the next word?

EDIT: I should note that e.Result.Text only returns words that can match Text in the dictionary.

+7
c # wpf speech-recognition speech-to-text
source share
3 answers

This is not like your situation. e.Result.Text represents something you can list: you test words that trigger text, not the whole text. In such cases, you should not use switch and instead of the chain if - then - else :

 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 ... 
+4
source share

Well, it cannot be used in switch on e.Result.Text , since it will check the whole value: Call Me John .

You must have a condition in case of default or outside of your switch

But I would really reorganize all this, trying to avoid switch or massive if..else if...else

 const string Callme = "call me"; var text = e.Result.Text; switch (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; } if (text.StartsWith(CallMe) userName = text.Replace(CallMe, string.Empty).Trim(); 
+4
source share

I would look at updating your grammar to use SemanticValues ​​so that you can directly retrieve the results, rather than analyze the recognition results. Here is an example here that demonstrates SemanticValues , SemanticResultKeys and SemanticResultValues .

+2
source share

All Articles