Search code examples
botframeworkspeech-recognitionazure-language-understandingazure-cognitive-servicesazure-speech

Full stop added by speech recognition at the end of the spoken sentence doesn't match action


I have developed a Virtual Assistant and am using the WebChat to test it with the Cognitive Speech Services. I have an issue: some responses from the bot include suggested actions like, for example,

"Choose a color"
"RED" "BLUE" "GREEN"

By typing in or clicking the chosen color everything is ok. If I use the speech with the microphone a "full stop" is added at the end of the sentence, i.e. "BLUE." This way LUIS doesn't recognize the answer and re-asks the question.

What is the best way to make it recognize correctly? Is there a way to disable the final full stop from being added by the speech engine? Or is there a better solution? (like normalizing punctuation in LUIS to make it ignore that or something else?)


Solution

  • You will want to scrub the activity of any punctuation after it has been received by your bot but before it is sent to and processed by LUIS. You can use the following regex to remove the unwanted characters (choose the characters you want to scrub...I included a lot) and to replace remaining stacked white spaces, like so:

    let text = turnContext.context.activity.text; let scrubbedText = text.replace(/[.,/#!$%\^&*;:{}=-_`~()]/g,""); const finalString = scrubbedText.replace(/\s{2,}/g," ");

    Then, update the activity.text with the scrubbed text and send it to LUIS.