0

I've done some coding on a virtual assistant, and I've hit a block. Here's the code:

 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!");
        }
    }

What I'm trying to do, as the title suggests, is have the name variable be filled in from the speech recognition. I'm looking for a way to do this that involves user input, and not adding each possibility for name separately. Unfortunately, the SpeechRecognizer is only looking at the "My Name Is", and nothing else.

Somebody told me about the garbage class, but I can't figure out how to implement it.

  • It's not clear to me what you're asking. Does `name` have a value? – Simon MᶜKenzie May 08 '15 at 01:50
  • Yes, its not shown. `String name = "testname";` I'm trying to match a sentence in a grammar, then an additional word that could be anything. I don't know how to get it to keep listening. – Minedude78910 May 08 '15 at 02:03
  • *additional word that could be anything* ? that *anything* is not a part of your grammar and unfortunately is not going to be recognized . – Nathan May 08 '15 at 02:10
  • How do I get it to be recognized? That is my real question here. How do I add it to a grammar? Can I used Regular Expressions or something? – Minedude78910 May 08 '15 at 02:13
  • @AmatuerDev Additional word that could be anything, such as a variable from the speech, but I can always get the whole text and replace the question format to extract the name. I just don't know how. – Minedude78910 May 08 '15 at 02:16
  • You could ofcourse ask the user to input his/her name before updating the *Grammar* in your *SpeechRecognizer.*. Say at program startup.. – Nathan May 08 '15 at 02:19
  • Ruins the experience, plus this code can be used for searching, looking up things, if only we knew how to get inputs like that... – Minedude78910 May 08 '15 at 02:38
  • I agree. Since you are creating a virtual assistant "look up" is an important aspect of information retrieval. On a side note, I wonder why you are storing the inputs and outputs inside your C# code instead of using any freely available Chatbot architecture. – Nathan May 08 '15 at 03:06

1 Answers1

0

What I ended up doing is adding in a dictation grammar and setting a timer. The timer is reset every time someone speaks. The dictation grammar goes into a textbox. When the timer = 0, use the code to check the textbox. Simple and done!