9 Replies - 847 Views - Last Post: 01 July 2015 - 02:28 PM Rate Topic: -----

#1 nman646   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 08-June 15

Why is my voice recognition getting confused? (Revised)

Posted 01 July 2015 - 08:57 AM

  if (r == "avias")
            {
                int randomNumber = random.Next(0, 3);

                int caseSwitch = (randomNumber);
                switch (caseSwitch)
                {
                    case 1:

                        say("Always here to assist you " + prefix + ".");

                        break;

                    case 2:

                        say("Yes " + prefix + "?");

                        break;

                    default:

                        say("At your service " + prefix + ".");

                        break;
                }

            }
            else if (r == "how are you avias")
            {
                int randomNumber = random.Next(0, 3);

                int caseSwitch = (randomNumber);
                switch (caseSwitch)
                {
                    case 1:

                        say("I am doing well, thank you for asking.");

                        break;

                    case 2:

                        say("Im having a terrible day at the moment, but avias still at your service.");

                        break;
                }
            } 

Ok, so this is a revision of my previous post to explain a little bit more of my problem. This code is a piece of my actual Artificial Intelligence. Whenever I say "How are you Avias?" It says the things in that if statement, but then once it finishes saying that stuff, then it will say the things that are contained in the "avias" if statement above the "how are you avias".

So what I am saying is that whenever I say "avias" in another command it will fire the two commands. I just dont want it to do that.

~Nman646

This post has been edited by Curtis Rutland: 01 July 2015 - 10:01 AM
Reason for edit:: fixed botched code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Why is my voice recognition getting confused? (Revised)

#2 nman646   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 08-June 15

Re: Why is my voice recognition getting confused? (Revised)

Posted 01 July 2015 - 09:22 AM

Also Whenever I say "avias" it repeats like 2 more times because often the say function says "avias at your service" and the microphone picks up the "avias" part and fires it again.
Was This Post Helpful? 0
  • +
  • -

#3 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Why is my voice recognition getting confused? (Revised)

Posted 01 July 2015 - 10:03 AM

That sounds like the problem, you're listening while the program is speaking. Disable the microphone during output, or at least stop processing input.

While I'm at it, I'm looking through the code you posted previously. You've got literally everything that this can do stuffed inside one method handler. That's not exactly the kind of code organization you should be shooting for.

You should consider setting up some kind of structure that lets you "key" responses. Like, a Dictionary. Dictionaries tie together "keys" and "values". For instance, if you have a list of strings you want to be available with an integer key, you could do this:

Dictionary<int, string> responses = new Dictionary<int, string>();
responses.Add(1, "This is response 1");
responses.Add(2, "This is response 2");
responses.Add(500, "This is another response");

//...later, in your code

string toSay = responses[2]; //toSay == "This is response 2"


You can leverage this to have much simpler structures for deciding what to output. You can even make a class that holds several of these dictionaries, so you can have different responses to different questions.

But building a bunch of nested branching statements for each potential question/response is the most naive way to try this.
Was This Post Helpful? 0
  • +
  • -

#4 nman646   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 08-June 15

Re: Why is my voice recognition getting confused? (Revised)

Posted 01 July 2015 - 12:36 PM

I have no clue how to turn off the microphone in c#. Any links or ideas on how to do it? Dictionaries seem pretty smart. Especially when i have thousands of responses. Thanks for the idea man!

~Nman646
Was This Post Helpful? 0
  • +
  • -

#5 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Why is my voice recognition getting confused? (Revised)

Posted 01 July 2015 - 01:01 PM

Remember that Dictionaries can be keyed by things other than numbers (and if you were going to use sequential numbers, an Array is likely more efficient in terms of size). You can use a Dictionary<string, string> and have things like this:

string response = myResponses["RX-58"];


Or some other type of object can be used. Also, Dictionary values don't have to be strings. It could be a list of strings (Dictionary<TypeOfKey, List<string>>), or some custom class that has its own decision logic (Dictionary<TypeOfKey, YourClassName>). I suggest looking them up on the MSDN to see how to use them correctly.

As to turning off the microphone...maybe that's overkill, but you must be telling your code to start listening/processing audio at some point. Research those components to see if they have a method to stop processing. While you are "outputting" audio, stop taking input.

Other than that, you'll have to post the code you're using to start listening. But I highly suggest looking your components up where you got them from (or the MSDN if they're Microsoft first party) and seeing what they expose for starting/stopping listening.
Was This Post Helpful? 0
  • +
  • -

#6 nman646   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 08-June 15

Re: Why is my voice recognition getting confused? (Revised)

Posted 01 July 2015 - 01:38 PM

Tried finding ways to mute and unmute microphone but im not having any luck... :(
Was This Post Helpful? 0
  • +
  • -

#7 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Why is my voice recognition getting confused? (Revised)

Posted 01 July 2015 - 01:42 PM

Like I said, forget the microphone. What class/component/whatever is actually doing your speech recognition? How are you telling it to start? Surely there will be a method to make it stop.
Was This Post Helpful? 0
  • +
  • -

#8 nman646   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 08-June 15

Re: Why is my voice recognition getting confused? (Revised)

Posted 01 July 2015 - 02:12 PM

 public Form1() //Initialze Setup
        {
            SpeechRecognitionEngine rec = new SpeechRecognitionEngine();

            cmds.Add(new string[] { "avias", "how are you", "date", "weather", "thank you", "shutdown computer", "log off"});

            Grammar gr = new Grammar(new GrammarBuilder(cmds));


            try
            {
                rec.RequestRecognizerUpdate();
                rec.LoadGrammar(gr);
                rec.SpeechRecognized += rec_SpeechRecognized;
                rec.SetInputToDefaultAudioDevice();
                rec.RecognizeAsync(RecognizeMode.Multiple);
            }
            catch { return; }

            this.Text = "A.V.I.A.S.";
            this.WindowState = FormWindowState.Normal;
            this.FormBorderStyle = FormBorderStyle.Sizable;
            this.WindowState = FormWindowState.Maximized;

            InitializeComponent();
        }




This is what I got...
Was This Post Helpful? 0
  • +
  • -

#9 Damage   User is offline

  • Lord of Schwing
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,989
  • Joined: 05-June 08

Re: Why is my voice recognition getting confused? (Revised)

Posted 01 July 2015 - 02:28 PM

Sounds like you're working from an example, do you have a link for it?
Was This Post Helpful? 0
  • +
  • -

#10 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Why is my voice recognition getting confused? (Revised)

Posted 01 July 2015 - 02:28 PM

https://msdn.microso...(v=vs.110).aspx

MSDN lists a few methods you might be able to leverage. That should always be your first stop when you have a question about a .NET component.

In fact, if you click into the method you're using to start recognition: https://msdn.microso...(v=vs.110).aspx

You see it explains that it will continue to recognize until you cancel it. You can either do that, or you can change your program to not do multiple, and just start listening again every time you finish responding.

At least, that's what I'd try. Part of programming is debugging, trying things, and doing research.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1