Skip to content

Commit

Permalink
Merge pull request #1182 from tomivm/feature/show-dialects-on-serbian…
Browse files Browse the repository at this point in the history
…-voices

Localize Serbian voices names
  • Loading branch information
martinbedouret authored Apr 21, 2022
2 parents 6ac4a77 + 6fdf1af commit 8c450b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/components/Settings/Speech/Speech.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ const styles = theme => ({
});

const getVoiceLabel = voice => {
const isSerbianVoice = voice.lang?.startsWith('sr');
if (!voice) {
return undefined;
}
if (voice.name === 'srpski Crna Gora') {
return voice.voiceURI;
}
return isCordova() ? voice.name + ' - ' + voice.voiceURI : voice.name;
return isCordova() && !isSerbianVoice
? voice.name + ' - ' + voice.voiceURI
: voice.name;
};

const Speech = ({
Expand Down
13 changes: 13 additions & 0 deletions src/providers/SpeechProvider/SpeechProvider.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ export function getVoices() {
let voices = [];
dispatch(requestVoices());
try {
const localizeSerbianVoicesNames = (voiceName, voiceLang) => {
if (voiceLang?.startsWith('sr')) {
const getNativeNameOfDialect = lang => {
if (lang === 'sr-ME') return 'Crnogorski jezik';
if (lang === 'sr-SP') return 'Српски језик';
if (lang === 'sr-RS') return 'Srpski jezik';
};
return `${voiceName} - ${getNativeNameOfDialect(voiceLang)}`;
}
return voiceName;
};

const pvoices = await tts.getVoices();
// some TTS engines do return invalid voices, so we filter them
const regex = new RegExp('^[a-zA-Z]{2,}-$', 'g');
Expand All @@ -184,6 +196,7 @@ export function getVoices() {
} else if (DisplayName) {
voice.name = `${DisplayName} (${voice.lang}) - ${Gender}`;
}
voice.name = localizeSerbianVoicesNames(voice.name, voice.lang);
return voice;
}
);
Expand Down

0 comments on commit 8c450b3

Please sign in to comment.