I am writing a WPF application that needs to recognize spoken commands from the user. Being new to the Speech Recognition Engine, I am unsure of how I can accomplish what I need to do the best way possible. The flow of the application would be as follows:
- User speaks a keyword to 'awaken' the app (ex Amazon Echo requiring the user to say 'Alexa')
- User speaks the command for the app to perform (ex "Play 'some song by some artist'")
My issue is that I am unsure what to do with my program after the keyword is recognized. If I were to play the song the user says after the keyword is spoken, would I need to start a new speech recognizer? This is some psuedo code of what I am doing:
private SpeechRecognitionEngine _listen;
public frmHome()
{
InitializeComponent();
SetupListen();
}
private void SetupListen()
{
ResetListener();
}
private void ResetListener()
{
_listen = new SpeechRecognitionEngine();
Choices exChoices = new Choices();
exChoices.Add(new String[] { "keyword" });
GrammarBuilder gb = new GrammarBuilder();
gb.Append(exChoices);
Grammar g = new Grammar(gb);
_listen.LoadGrammar(g);
_listen.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sr_speechRecognized);
_listen.SetInputToDefaultAudioDevice();
_listen.RecognizeAsync();
}
private void sr_speechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text.Equals("keyword"))
{
//start listening for the command
}
ResetListener();
}