SpeechSynthesis.getVoices() cannot retrieve available audio

Asked 1 years ago, Updated 1 years ago, 368 views

I ran getVoices() of the Web Speech API with the following code in chrome, but it returned with an empty array.How can I get it?

const voice=speechSynthesis.getVoices();
console.log(voice);

<·[]// Console Results

By the way, Chrome supports speechSynthesis, and when you execute the above code on the console, it returns the array properly.

javascript google-chrome

2023-03-13 06:16

1 Answers

Wait for the voiceschanged event before running.Your voice may not be ready immediately after the page loads.

speechSynthesis.addEventListener('voiceschanged', e=>{
  const voice = speechSynthesis.getVoices();
  console.log(voice);
});


2023-03-13 12:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.