2
Reply

C# WPF Speech recognition not working.

abhishek jain

abhishek jain

Jun 19 2014 5:43 AM
1.3k
The event does not fire up i.e.  no message box is shown up on speaking the words. Not sure about whether  even the engine started or not.
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Speech;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Threading;
namespace Summerproject_trial
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private SpeechRecognitionEngine recEngine = new SpeechRecognitionEngine();
public MainWindow()
{
InitializeComponent();
Choices mychoices = new Choices();
mychoices.Add(new string[] {"Ok","Test","Hello"});
GrammarBuilder gb = new GrammarBuilder();
gb.Append(mychoices);
Grammar mygrammar = new Grammar(gb);
recEngine.LoadGrammarAsync(mygrammar);
recEngine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(recEngine_SpeechRecognized);
recEngine.SetInputToDefaultAudioDevice();
}
void recEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
MessageBox.Show("You said: "+e.Result.Text);
//throw new NotImplementedException();
}
}
}
 

Answers (2)