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

Counting the number of words recognized

posted Jul 27, 2016 05:30:13 by Pritcharduino
Good day!

I was wondering if it is possible for an Arduino to identify how many words MOVI has recognized. Using the Low Level Interface in the serial monitor, it is visible to the user as to how many words MOVI had recognized from a given vocabulary, but is this known to the MOVI board automatically? Any help or advice would be greatly appreciated!

Building human-scale anthropomorphic robots.
page   1
2 replies
GeraldFriedland said Jul 27, 2016 19:03:11
You can get the raw words that you see in the Serial Monitor by catching the RAW_WORDS event and then using the method getResult(). Then, just count the words. The event SILENCE tells you no words.

This is how a simple word counter could look like:

void loop() // run over and over
  signed int res=recognizer.poll(); // Get result from MOVI, 0 denotes nothing happened, 
                                    // negative values denote events (see User Manual)
  if (res==RAW_WORDS) {             // The event raw_words let's us get the words via getResult()
    String result=recognizer.getResult();  // Get the result and save it in a string
    int numwords=1;                        // If we end up here, we have at least one word
    for (int i=0;i<result.length();i++)  { // Go through the result string...
      if (result[i]==' ') numwords++;         // ... and count spaces (= words).
    recognizer.say("I heard "+String(numwords)+" words.");  // Say how many words we have.
  if (res==SILENCE) {               // The event SILENCE means there were no words
    recognizer.say("I heard 0 words.");  // Say we have 0 words.

You can replace this loop() in WordSequence2 for example, to get a reply from MOVI about how many numbers you spoke. To get rid of the "I didn't understand you message" in the event of a SILENCE event, just add

to the setup method after train().

Let me know if this helps.
[Last edited Jul 27, 2016 19:08:39]
Pritcharduino said Jul 28, 2016 03:07:55
That method worked for me, thank you very much Gerald! I look forward to posting my finished project here sometime soon!
Building human-scale anthropomorphic robots.
Login below to reply: