Skip to content

Commit

Permalink
🐛 fix: Fix speechSynthesisVoiceList
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Nov 16, 2023
1 parent ea0cff5 commit 093649f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/core/SpeechSynthesisTTS/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import voiceLocale from '@/core/data/locales';
import speechSynthesisVoiceList from './voiceList';

const genSpeechSynthesisVoiceList = () => {
if (!SpeechSynthesis) return;
if (!SpeechSynthesis) return speechSynthesisVoiceList;
const data = SpeechSynthesis?.getVoices();
if (!data) return speechSynthesisVoiceList;
const localeKeys = Object.keys(voiceLocale);
const list: any = {};
for (const voice of data) {
Expand All @@ -22,11 +23,9 @@ const genSpeechSynthesisVoiceList = () => {
};

export const getSpeechSynthesisVoiceOptions = (locale?: string): SelectProps['options'] => {
const speechSynthesVoiceList = genSpeechSynthesisVoiceList();
const voiceList = genSpeechSynthesisVoiceList();
const data: string[] =
locale && speechSynthesVoiceList?.[locale]
? speechSynthesVoiceList?.[locale] || []
: flatten(Object.values(speechSynthesVoiceList));
locale && voiceList?.[locale] ? voiceList?.[locale] || [] : flatten(Object.values(voiceList));

return data.map((voice) => ({ label: voice, value: voice }));
};

0 comments on commit 093649f

Please sign in to comment.