Skip to content
Advertisement

How to perform regular expressions on a Speech Recognition transcript?

Summary of my application:

  1. Input: Have the user speak to the computer (ask the computer "What is your name?") ✅
  2. Perform a regular expression on the ‘transcript’ result (from webkitSpeechRecognition) ❌
  3. Output: console.log("My name is Harry Johnson"). ❌

I’m trying to perform a regular expression on a speech recognition transcript, as follows:

JavaScript

The above works fine and I am able to console.log the transcript/speech from the user. The problem arises from the below code and I think it has something to do with the fact that the transcript has to be a string? I have tried converting the transcript to a string using String(transcript) and transcript.toString(), but I’m still not achieving my result: which is for the computer to console.log “My name is Harry Johnson”.

JavaScript

The regular expression is correct, the main problem is with the transcript variable. If anyone has any advice on why the console.log("My name is Harry Johnson") function is not being performed, it would be greatly appreciated if you could share that with me! 🙂

Thanks!

Advertisement

Answer

for me I just put the speakBackToMe(); line below console.log(transcript); within the result event listener block and it worked

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement