Spaces:
Running
Running
File size: 851 Bytes
803d869 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | // convomate/src/components/Sections/voiceUtils.js
export const loadVoices = () => {
return new Promise((resolve) => {
const voices = window.speechSynthesis.getVoices();
if (voices.length > 0) {
resolve(voices);
} else {
window.speechSynthesis.onvoiceschanged = () => {
resolve(window.speechSynthesis.getVoices());
};
}
});
};
export const getDefaultVoice = (voices) => {
// Try to find Google US English first
const googleUS = voices.find(
(voice) =>
voice.name.includes("Google US English") ||
voice.name.includes("English United States"),
);
// Fallback to first English voice
const englishVoice = voices.find(
(voice) => voice.lang.includes("en-US") || voice.lang.includes("en_GB"),
);
return googleUS || englishVoice || voices[0];
};
|