如何向语音识别添加变量?
How do I add variables to Speech Recognition?
我在虚拟助手上完成了一些编码,但遇到了障碍。这是代码:
private void Form1_Load_1(object sender, System.EventArgs e)
{
SrgsDocument commands = new SrgsDocument();
SrgsRule displayList = new SrgsRule("selectList");
SrgsOneOf listTypes = new SrgsOneOf(new string[] { "hi " + name + ", my name is" , "hi " + name});
displayList.Scope = SrgsRuleScope.Public;
displayList.Elements.Add(listTypes);
commands.Rules.Add(displayList);
commands.Root = displayList;
Grammar grammar = new Grammar(commands);
recEngine.LoadGrammarAsync(grammar);
recEngine.SetInputToDefaultAudioDevice();
recEngine.RecognizeAsync(RecognizeMode.Multiple);
recEngine.SpeechRecognized +=recEngine_SpeechRecognized;
}
SpeechSynthesizer synth = new SpeechSynthesizer();
void recEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
String message = e.Result.Text.ToLower();
if (message.Contains("hi " + name + ", my name is"))
{
message = message.Replace("hi " + "name" + ", my name is", "");
synth.Speak("Hello " + message + ", my name is " + name);
}
else if (message.Contains("hi " + name))
{
synth.Speak("Hello!");
}
}
正如标题所示,我正在尝试做的是从语音识别中填充名称变量。我正在寻找一种涉及用户输入的方法,而不是单独添加名称的每种可能性。不幸的是,SpeechRecognizer 只查看 "My Name Is",没有别的。
有人告诉我垃圾问题 class,但我不知道如何实施。
我最后做的是添加听写语法和设置计时器。每次有人说话时,计时器都会重置。听写语法进入文本框。当计时器 = 0 时,使用代码检查文本框。简单又大功告成!
我在虚拟助手上完成了一些编码,但遇到了障碍。这是代码:
private void Form1_Load_1(object sender, System.EventArgs e)
{
SrgsDocument commands = new SrgsDocument();
SrgsRule displayList = new SrgsRule("selectList");
SrgsOneOf listTypes = new SrgsOneOf(new string[] { "hi " + name + ", my name is" , "hi " + name});
displayList.Scope = SrgsRuleScope.Public;
displayList.Elements.Add(listTypes);
commands.Rules.Add(displayList);
commands.Root = displayList;
Grammar grammar = new Grammar(commands);
recEngine.LoadGrammarAsync(grammar);
recEngine.SetInputToDefaultAudioDevice();
recEngine.RecognizeAsync(RecognizeMode.Multiple);
recEngine.SpeechRecognized +=recEngine_SpeechRecognized;
}
SpeechSynthesizer synth = new SpeechSynthesizer();
void recEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
String message = e.Result.Text.ToLower();
if (message.Contains("hi " + name + ", my name is"))
{
message = message.Replace("hi " + "name" + ", my name is", "");
synth.Speak("Hello " + message + ", my name is " + name);
}
else if (message.Contains("hi " + name))
{
synth.Speak("Hello!");
}
}
正如标题所示,我正在尝试做的是从语音识别中填充名称变量。我正在寻找一种涉及用户输入的方法,而不是单独添加名称的每种可能性。不幸的是,SpeechRecognizer 只查看 "My Name Is",没有别的。
有人告诉我垃圾问题 class,但我不知道如何实施。
我最后做的是添加听写语法和设置计时器。每次有人说话时,计时器都会重置。听写语法进入文本框。当计时器 = 0 时,使用代码检查文本框。简单又大功告成!