I'm building an application that recognizes multiple words from a user; thus putting together a sentence using the words recognized.
Here's what I have as of now:
namespace SentenceRecognitionFramework__v1_
{
public partial class Form1 : Form
{
SpeechRecognitionEngine recog = new SpeechRecognitionEngine();
SpeechSynthesizer sp = new SpeechSynthesizer();
public Form1()
{
InitializeComponent();
}
private void btnListen_Click(object sender, EventArgs e)
{
Choices sList = new Choices();
sList.Add(new String[] { "what","is", "a", "car" });
Grammar gr = new Grammar(new GrammarBuilder(sList));
recog.RequestRecognizerUpdate();
recog.LoadGrammar(gr);
recog.SpeechRecognized += sRecognize_SpeechRecognized;
recog.SetInputToDefaultAudioDevice();
recog.RecognizeAsync(RecognizeMode.Multiple);
recog.SpeechRecognitionRejected += sRecognize_SpeechRecognitionRejected;
}
private void sRecognize_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e)
{
sentenceBox.Text = "Sorry, I couldn't recognize";
}
private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
sentenceBox.Text = e.Result.Text.ToString();
}
}
}
HOWEVER, this code will only recognize one word at a time. Even if I edit my code to do this:
private void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
sentenceBox.Text = sentenceBox.Text + " " + e.Result.Text.ToString();
}
The application cannot continuously recognize words when I utter the words "What is a car" continuously without having breaks when I speak them out.
What changes can I make in order for the program to recognize an entire sentence built using those words defined, without having to have speech breaks when uttering the sentence?
Output required:
I utter the sentence: What is a car
Application displays: What is a car
PERFECT Example: Google Speech Recognition Google develops a sentence using the words available in their word library
Thank you kindly :)
It recognizes one word because you incorrectly constructed the grammar. Since you constructed the grammar consisting of choice of one of the words "what", "is", "a", "car" it exactly recognizes one of the words.
You probably want to read introduction into grammars and related documentation.
http://msdn.microsoft.com/en-us/library/hh378438(v=office.14).aspx
If you want to construct the grammar describing the phrase you can just use GrammarBuilder like this:
This grammar will recognize a phrase.
To understand how Choices work you can read documentation on Choices:
http://msdn.microsoft.com/en-us/library/microsoft.speech.recognition.choices(v=office.14).aspx
This answer may be a little late, but I have not found any other place with an actual answer to this problem. So to save others the the time and frustration, here is how I did it.
The key here is this line
This tells the speech recognizer to recognize, up to 4 repetitions of elements form
builder
, and a minimum of zero.So it will now recognize
And if you want more than 4 repetitions, just change
new GrammarBuilder(builder, 0, 4)
to
See this for more info GrammarBuilder(builder, minRepeat, maxRepeat)