我希望我的语法中有一个“搜索X”,下面的代码可以正常工作,但只有一部分可以说,当输入为Search *
时,我的输入为Search ABC
private void Form1_Load(object sender, EventArgs e)
{
Choices commands = new Choices();
commands.Add(new string[] { @"search *" });
GrammarBuilder gBuilder = new GrammarBuilder();
gBuilder.Append(commands);
gBuilder.Culture = new System.Globalization.CultureInfo("en-GB");
Grammar grammar = new Grammar(gBuilder);
recEngine.LoadGrammarAsync(grammar);
recEngine.SetInputToDefaultAudioDevice();
recEngine.SpeechRecognized += RecEngine_SpeechRecognized;
}
private void RecEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text == @"search *")
{
synthesizer.SpeakAsync(e.Result.Text);
}
}
谢谢!