如何在语音识别中添加变量?

时间:2015-05-08 01:41:33

标签: c# variables text-to-speech speech garbage

我已经在虚拟助手上完成了一些编码,而且我遇到了障碍。这是代码:

 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仅查看“我的名字是”,而不是其他任何内容。

有人告诉我垃圾级别,但我无法弄清楚如何实现它。

0 个答案:

没有答案