we have started to play about with the speechRecognitionEngine, and built a very basic app based on one that we found on stack overflow. Code below:-
public partial class Form1 : Form
{
SpeechRecognitionEngine sr = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));
public Form1()
{
InitializeComponent();
// Create an in-process speech recognizer for the en-US locale.
}
private void BeginSpeach()
{
//Create grammar
Choices words = new Choices();
words.Add("Hi");
words.Add("No");
words.Add("Yes");
Grammar wordsList = new Grammar(new GrammarBuilder(words));
wordsList.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(rec_SpeechRecognized);
sr.LoadGrammar(wordsList);
sr.SetInputToDefaultAudioDevice();
sr.RecognizeAsync();
}
void rec_SpeechRecognized(object sender, RecognitionEventArgs e)
{
MessageBox.Show(e.Result.Text);
}
private void Form1_Load(object sender, EventArgs e)
{
BeginSpeach();
}
}
This seems to work great. The only issue is that once it has detected the word "hi", thats is, it won't defect any more. Is there a way to get this to always listen? so i can say "hi", then "no", then "yes".
We hope to build on this to create a list of commands
Thank you for any advice
Came to the conclusion from tweellt.
sr.RecognizeCompleted += new EventHandler<RecognizeCompletedEventArgs>(rec_test);
and then calling this again
private void rec_test(object sender, RecognizeCompletedEventArgs e)
{
sr.RecognizeAsync();
}
You could just change
sr.RecognizeAsync();
in BeginSpeach()
to
sr.RecognizeAsync(RecognizeMode.Multiple);
This will detect everything you say...
RecognizeAsync() - Performs a single, asynchronous speech recognition operation.
RecognizeAsync(RecognizeMode) - Performs one or more asynchronous speech recognition operations.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.