I'm trying to use SpeechRecognitionEngine()
. When I say hello the program should respond with hi. The problem is when I run the program the there is an error:
Additional information: The language for the grammar does not match the language of the speech recognizer.
I don't know how to fix that on windows form application. Can someone help? Another problem is even if I make the program speech the voice gender is not female. Why is that?
Thanks in advance.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Speech.Synthesis;
using System.Speech.Recognition;
namespace test1
{
public partial class Form1 : Form
{
SpeechSynthesizer s = new SpeechSynthesizer();
Choices list = new Choices();
public Form1()
{
SpeechRecognitionEngine rec = new SpeechRecognitionEngine();
list.Add("hello");
Grammar gr = new Grammar(new GrammarBuilder(list));
rec.RequestRecognizerUpdate();
rec.LoadGrammar(gr);
rec.SpeechRecognized += rec_SpeechRecognized;
rec.SetInputToDefaultAudioDevice();
rec.RecognizeAsync(RecognizeMode.Multiple);
InitializeComponent();
}
private void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
s.SelectVoiceByHints(VoiceGender.Female);
String r = e.Result.Text;
if ( r == "hello" )
{
s.Speak("hi");
}
}
}
}