File size: 686 Bytes
1896b82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
export function getSpeechSynthesisVoice(speechSynthesis: SpeechSynthesis): SpeechSynthesisVoice {
  const allVoices = speechSynthesis.getVoices()

  console.log("all voices:")
  console.table(allVoices)

  const fallbackVoice = allVoices[0]

  const enVoices = allVoices.filter(voice => voice.lang.toLowerCase() === "en-us")

  console.log("available english voices:")
  console.table(enVoices)

  const kathyVoice = enVoices.find(voice => voice.name.includes("Kathy"))

  // if we find a high-quality voice
  const googleVoice = enVoices.find(voice => voice.name.includes("Google"))

  // console.log("google voice:", googleVoice)

  return googleVoice || kathyVoice || fallbackVoice
}