Voice Recognition buf value and other concerns

Hello everyone, I have some questions regarding the values and codes for voice recognition. I’m trying to control LED using a voice command (specifically, a “time” voice command). I already trained this “time” command as record 0 and load this record to the recognizer (see cxem.net/house/files/1-412_FZ0475.pdf). So when I speak “time” the VR recognizes and gives a certain value. But I don’t know what exactly is this value. Below are the methods being used that are taken from VR library reference:

/**
@brief VR class constructor.
@param receivePin → software serial RX
transmitPin → software serial TX
/
VR::VR(uint8_t receivePin, uint8_t transmitPin) : SoftwareSerial(receivePin, transmitPin)
/
*
@brief VR class constructor.
@param buf → return data .
buf[0] → Group mode(FF: None Group, 0x8n: User, 0x0n:System
buf[1] → number of record which is recognized.
buf[2] → Recognizer index(position) value of the recognized record.
buf[3] → Signature length
buf[4]~buf[n] → Signature
timeout → wait time for receiving packet.
@retval length of valid data in buf. 0 means no data received.
*/
int VR :: recognize(uint8_t *buf, int timeout)

/**
@brief Load one record to recognizer.
@param record → record value.
buf → pointer of return value buffer, optional.
buf[0] → number of records which are load successfully.
buf[2i+1] → record number
buf[2i+2] → record load status.
00 → Loaded
FC → Record already in recognizer
FD → Recognizer full
FE → Record untrained
FF → Value out of range"
(i = 0 ~ ‘(retval-1)/2’ )
@retval ‘>0’ → length of valid data in buf.
0 → success, buf=0, and no data returned.
‘<0’ → failed.
*/
int VR :: load(uint8_t record, uint8_t *buf)

Here are the concerns:

  1. What is exactly the value of myVR.load((uint8_t)timeRecord) so that I can compare it to zero and make the statement true?

  2. What is exactly the value of buf? (from the line, ret = myVR.recognize(buf,50))

  3. If buf is the return value, what is that value it refers to? and what is that value when I speak “time”?

  4. What is the value being stored in the variable “ret” after having a return value buf?

  5. What is meant by “length of valid data in buf”? (refer the line @retval)

  6. Where exactly is this buf value occurs during the process?

Your ideas to share are very much appreciated. Thank you.

Here are the codes:

#include <SoftwareSerial.h>
#include "VoiceRecognitionV3.h"

/**        
 Connection
 Arduino    VoiceRecognitionModule
  2   ------->     TX
  3   ------->     RX
*/
VR myVR(2,3);    // 2:RX 3:TX, you can choose your favourite pins.

uint8_t records[7]; // save record
uint8_t buf[64];

int const ledTime = 13

#define timeRecord (0)

void setup() {
 /** initialize */
 myVR.begin(9600);
 
 Serial.begin(115200);
 Serial.println("Elechouse Voice Recognition V3 Module\r\nControl LED sample");
 
 pinMode(ledTime, OUTPUT); digitalWrite(ledTime, HIGH);
   
 if(myVR.clear() == 0){
   Serial.println("Recognizer cleared.");
 }else{
   Serial.println("Not find VoiceRecognitionModule.");
   Serial.println("Please check connection and restart Arduino.");
   while(1);
 }
 if(myVR.load((uint8_t)timeRecord) >= 0){
   Serial.println("timeRecord loaded");
 }

}

void loop() {
 int ret;
 ret = myVR.recognize(buf, 50);
 if(ret>0){
   switch(buf[1]){
     case timeRecord:
       digitalWrite(led, LOW);
       delay(1000);
       digitalWrite(led, HIGH);
       break;
     default:
       Serial.println("Record function undefined");
       break;
   }
   /** voice recognized */
   printVR(buf);
 }
}

VR3 Library Reference.pdf (55.3 KB)

fxlnxjude:

  1. What is exactly the value of myVR.load((uint8_t)timeRecord) so that I can compare it to zero and make the statement true?

It says in the document you quote above: Since you pass no pointer for 'buf' the return value is 0 if the operation was successful or a negative number if the operation was not successful.

fxlnxjude:
2. What is exactly the value of buf? (from the line, ret = myVR.recognize(buf,50))

That is shown in the document. It is a five or more byte array:

buf[0] --> Group mode (FF:None Group, 0x8n: User, 0x0n: System)
buf[1] --> number of the record which is recognized.
buf[2] --> Recognizer index (position) of the recognized value.
buf[3] --> Signature length
buf[4]-buf[n] --> Signature

fxlnxjude:
3. If buf is the return value, what is that value it refers to?

There are five values in the array. I think buf[1] is the number you assigned to your record.

fxlnxjude:
and what is that value when I speak "time"?

I think you said you assigned 'time' the value 0.

fxlnxjude:
4. What is the value being stored in the variable "ret" after having a return value buf?

The length of 'buf'.

fxlnxjude:
5. What is meant by "length of valid data in buf"? (refer the line @retval)

I think it means the number of bytes of 'buf' that were used: the four fixed bytes plus the signature.

fxlnxjude:
6. Where exactly is this buf value occurs during the process?

It appears to be a variable that you create: uint8_t buf[64];

Are there no examples you can follow?

johnwasser:
Since you pass no pointer for 'buf' the return value is 0 if the operation was successful

Sir, what do you mean by "pass no pointer for buf"? Is there any proof that I did pass no pointer for buf?

fxlnxjude:
Sir, what do you mean by "pass no pointer for buf"? Is there any proof that I did pass no pointer for buf?

The proof is your code: if(myVR.load((uint8_t)timeRecord) >= 0){
The document you quoted shows the declaration of .load():int VR :: load(uint8_t record, uint8_t *buf)
The pointer to the buffer would have been the second argument. You did not provide a second argument. That proves you did pass no pointer for buf. If you want to pass a pointer for buf, that would be easy:  if(myVR.load((uint8_t)timeRecord, buf) >= 0){

So if the return value is 0, it is successful whether I pass a pointer for 'buf' or not? and what about if the return value is >0? When can we have this value?

fxlnxjude:
So if the return value is 0, it is successful whether I pass a pointer for ‘buf’ or not? and what about if the return value is >0? When can we have this value?

@retval ‘>0’ → length of valid data in buf.
0 → success, buf=0, and no data returned.
‘<0’ → failed.