I'm making a C# program which uses System.Speech.Recognition and I need to save the words said at a point in my code. Such as the user can say "Google cats" and it would save "cats" to a string this way I can use this string to Google search the string which in this case is "cats". My code so far can be found here.
Asked
Active
Viewed 177 times
0
-
1Unlike forum sites, we don't use "Thanks", or "Any help appreciated", or signatures on [so]. See "[Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts). – John Saunders Dec 13 '13 at 02:23
-
Why? That makes me feel like I'm not talking to humans. Imagine if I was at the library asking the librarian where a book was and I just said "Where's Moby Dick?" and when he or she's done just leave. Is there a special reason why we can't use "Hi" || "Thanks"? – StackOverload Dec 13 '13 at 02:29
-
3We are not having a discussion here. This is not a discussion forum. It's a Q&S site. Please take the time to read the [faq] and [ask] and learn how things work here. The fact that we do things differently is the _reason_ the site is so successful. – John Saunders Dec 13 '13 at 02:30
-
1And, BTW, when people post links, they generally mean for you to read them. – John Saunders Dec 13 '13 at 02:31
-
I did read it. I'm just saying, I respect your authority. It just feels unhuman to not start off anything without a greeting. – StackOverload Dec 13 '13 at 02:35
-
2You clearly didn't read it well. Again, we are not having a conversation here. You ask a question, you get an answer, maybe not right away. Someone asks a question four years from now, they get the same answer you got today. – John Saunders Dec 13 '13 at 02:37
-
2My personal theory is that stripping salutations from questions probably increases SO's hit rate on Google, a good thing IMO. – Mark Feldman Dec 13 '13 at 03:04
-
possible duplicate of [Get user input from Speech?](http://stackoverflow.com/questions/17878565/get-user-input-from-speech) – Nikolay Shmyrev May 28 '15 at 13:27
1 Answers
1
You can do this by loading a grammar that matches google <any text>
. Create a grammar builder, append google
and append dictation.
Put this at the point where you load grammars:
GrammarBuilder googleGrammarBuilder = new GrammarBuilder();
googleGrammarBuilder.Append("google ");
googleGrammarBuilder.AppendDictation();
listener.LoadGrammar(new Grammar(googleGrammarBuilder) { Enabled = true });
And put this in your SpeechRecognized
method:
if (e.Result.Text.StartsWith("google "))
{
string googleQuery = e.Result.Text.Remove(0, 7);
System.Diagnostics.Process.Start(String.Concat("http://google.com/search?q=", googleQuery));
}
The Process.Start
line will open your default browser with the Google link.

ProgramFOX
- 6,131
- 11
- 45
- 51