twiliospeech-recognitionivrtwilio-studio

Twilio Studio Say/Gather Hints


We are using the Twilio Studio for managing our IVR flows, and have come across an issue when recognising particular numbers.

Example: A verification code that has 22 in it, is being recognised by Twilio as "tutu"

Aside from changing the settings like "recognition language", I'd like to get Twilio to recognise numbers more than other inputs. There is the option for "Speech Recognition Hints" which is a comma separate list of values - but what should you put in there? The documentation just talks about a comma separated list, nothing else!

Any help gratefully received.

Thanks in advance


Solution

  • You could see if entering $OOV_CLASS_DIGIT_SEQUENCE in the hints section has any impact on the captured SpeechResult.

    Another option is to run the result through a normalization Twilio Function that converts tutu to 22.

    I would recommend DTMF when capturing digits, to avoid this.

    // converts number words to integers (e.g. "one two three" => 123)
    
    function convertStringToInteger( str ) {
        let resultValue = "";
        let arrInput = [];
        let valuesToConvert = {
            "one": "1",
            "two": "2",
            "to": "2",
            "three": "3",
            "four": "4",
            "five": "5",
            "six": "6",
            "seven": "7",
            "eight": "8",
            "nine": "9",
            "zero": "0"
        };
    
        str = str.replace(/[.,-]/g," ");  // sanitize string for punctuation
    
        arrInput = str.split(" ");      // split input into an array
    
        // iterate through array and convert values
        arrInput.forEach( thisValue => {
          if( ! isNaN(parseInt(thisValue)) ) {  // value is already an integer
            resultValue += `${parseInt(thisValue)}`;
    
          } else {  // non-integer
            if( valuesToConvert[thisValue] !== undefined) {
              resultValue +=  valuesToConvert[thisValue];
            } else {
              // we don't know how to interpret this number..
              return false;
            }
          }
        });
    
        console.log('value converted!', str, ' ====> ', resultValue);
        return resultValue;
    }