Members | Sign In
Legacy MOVI User Community Forum (readonly) > MOVI Question & Answers
avatar

Preventing Gibberish Input

posted Apr 14, 2016 13:18:32 by Splitfirz Awesome
Hi,

I'm trying to create a "if" condition when MOVI detects random words (not predefined) from the set-up.
In those cases, Movi should ideally prompt the user to speak again. Here's what I did, using the RAW_WORDS and UNKNOWN_SENTENCE events. However, what happens now is that MOVI does do what it was intended to do, but goes on to say other event triggers after doing so. EG. When a non-registered sentence is spoken, it says "Sorry, i do not understand you". But then, it proceeds to randomly say results from other events such as "You're most welcome" which is by right from another case scenario.

Am I doing this correctly?
Thank you

``````````code`````````````
//predefined sentences trained at the top.
.
...
.....

if (result==8) {
recognizer.say(F("You're most welcome"));
recognizer.say(F("Have a great day ahead!"));
}

if (result==RAW_WORDS){
recognizer.say(F("Sorry, I couldn't hear you well"));
recognizer.ask(F("Please try again"));
}

if (result==UNKNOWN_SENTENCE){
recognizer.say(F("Sorry, I couldn't hear you well"));
recognizer.ask(F("Please try again"));
}
[Last edited Apr 14, 2016 13:19:00]
page   1
2 replies
avatar
GeraldFriedland said Apr 14, 2016 21:27:12
So what happens here is that each recognition cycle generates several lines of events. So you will ALWAYS get the RAW_WORDS and (a sentence or UNKNOWN_SENTENCE) result. So in your case, you'll always trigger RAW_WORDS, no matter what and then either one of your 8 sentences or UNKNOWN_SENTENCE.

Here is three ways of achieving what you are trying to do:
1) You use MOVI's sentence recognizer that will always try to match the words to the closest sentence unless there is ambiguity and only ask again if there is either silence (nothing said) or if there is ambiguity in the matching:
void loop()
{
   ...
   if (result==8) { 
      recognizer.say(F("You're most welcome")); 
      recognizer.say(F("Have a great day ahead!"));  
   } 
   if (result==UNKNOWN_SENTENCE || result==SILENCE){ 
      recognizer.say(F("Sorry, I couldn't hear you well")); 
      recognizer.ask(F("Please try again")); 
   }
}


The downside of this method is that you'll often have jibberish matched to sentences, no matter what.

2) You bypass the sentence matching and try your own match:
String words;
void loop() 
{
   ...
   if (result==RAW_WORDS){ 
      words=recognizer.getResult()
      // do something with the words directly
   ...
   } 
   if (result==SILENCE){ 
      recognizer.say(F("Sorry, I couldn't hear you well")); 
      recognizer.ask(F("Please try again")); 
   }
}


The best method as you can implement all sorts of intelligence into your sentence matching base don your concrete use case, rather than going with MOVI's default. The downside is: It's complicated.

3) You use the sentence recognizer and train a 'background model' (see user manual and also our wordspotter example in the library):
void setup()
{
   ...
   recognizer.addSentence(...) // your sentences 1
   ...
   recognizer.addSentence(...) // your sentences 8
   // Add the top-50 most frequent English words as 'background model'.
   // This way, the wanted sentences are less likely to be matched to random jibberish.
   // See MOVI's user manual for a more detailed explanation on this.
   recognizer.addSentence(F("the be to of and a"));
   recognizer.addSentence(F("in that have I it for"));
   recognizer.addSentence(F("not on with he as you"));
   recognizer.addSentence(F("do at this but his by"));
   recognizer.addSentence(F("from they we say her she"));
   recognizer.addSentence(F("or an will my one all would"));
   recognizer.addSentence(F("there their what so up out"));
   recognizer.addSentence(F("if about who get which go me"));
   ...
}

void loop()
{
   ...
   if (result==8) { 
      recognizer.say(F("You're most welcome")); 
      recognizer.say(F("Have a great day ahead!")); 
   } 
   if (result>8 || result==UNKNOWN_SENTENCE || result==SILENCE) {
      recognizer.say(F("Sorry, I couldn't hear you well")); 
      recognizer.ask(F("Please try again")); 
   }
   ...
}


Your background model might need adjustment depending on what kind of jibberish is most likely expected. Also if your command sentences are very long, this model might not work so well. Of course, you can also somewhat combine the three methods.

Let me know if that helped.
[Last edited Apr 14, 2016 21:36:28]
avatar
Splitfirz Awesome said Apr 15, 2016 02:58:16
Great! thank you for this fix! =)
Login below to reply: