0

I have a global variable that I am passing into a function. The function should feed/generate some values to that variable. So far, I tried:

var final_transcript = "";
function test1(x) {
  recognition.onresult = function(event) {
    x += event.results.transcript;
  }
}

StartButton.addEventListener("click", () => {
  test1(final_transcript);
})

EndButton.addEventListener("click", () => {
  console.log(final_transcript);
})

In this case, assuming StartButton is clicked before EndButton. So the StartButton initiate the function that feeds in strings that add into the global variable final_transcript. when EndButton is clicked, the variable final_transcript should contain all the strings fed in. But the value of final_transcript is still empty according to the console log.

EDIT: recognition.onresult transcript the user's voice into text. It is a real-time event.

The reason why I am doing this is that the function test1 cannot detect an end event. Only EndButton.addEventListener does, and I cannot add it in test1 function.

gshow8 shac
  • 391
  • 2
  • 15

0 Answers0