Updated options ui styles, and browser tts voice selection.
This commit is contained in:
@@ -547,13 +547,67 @@ export class BrowserTTSHandler extends TTSHandler {
|
||||
* @returns {Array} - Array of voice objects
|
||||
*/
|
||||
getVoices() {
|
||||
return this.voices.map(voice => ({
|
||||
// Get localization module for current locale
|
||||
const localization = this.getModule('localization');
|
||||
let currentLocale = localization ? localization.getLocale().toLowerCase() : 'en-us';
|
||||
|
||||
// Create language code variations for matching
|
||||
const languageCode = currentLocale.split('-')[0]; // e.g., 'en' from 'en-us'
|
||||
|
||||
// Filter voices by current locale
|
||||
const filteredVoices = this.voices.filter(voice => {
|
||||
const voiceLang = voice.lang.toLowerCase();
|
||||
return voiceLang.startsWith(languageCode) ||
|
||||
voiceLang === currentLocale ||
|
||||
// For handling cases like 'en' matching 'en-us'
|
||||
(currentLocale.startsWith(voiceLang) && voiceLang.length === 2);
|
||||
});
|
||||
|
||||
// If no matching voices found, fall back to all voices
|
||||
const voicesToUse = filteredVoices.length > 0 ? filteredVoices : this.voices;
|
||||
|
||||
return voicesToUse.map(voice => ({
|
||||
id: voice.voiceURI,
|
||||
name: voice.name,
|
||||
language: voice.lang
|
||||
lang: voice.lang,
|
||||
// Add proper gender field if available, otherwise infer from name
|
||||
gender: this.inferVoiceGender(voice.name)
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Infer voice gender from name
|
||||
* @param {string} name - Voice name
|
||||
* @returns {string} - Inferred gender ('male', 'female', or 'unknown')
|
||||
*/
|
||||
inferVoiceGender(name) {
|
||||
const lowerName = name.toLowerCase();
|
||||
|
||||
// Common terms indicating gender
|
||||
const maleTerms = ['male', 'man', 'guy', 'boy', 'mr', 'sir', 'him', 'his'];
|
||||
const femaleTerms = ['female', 'woman', 'lady', 'girl', 'ms', 'mrs', 'miss', 'her', 'hers'];
|
||||
|
||||
// Check for explicit gender terms in the name
|
||||
for (const term of maleTerms) {
|
||||
if (lowerName.includes(term)) return 'male';
|
||||
}
|
||||
|
||||
for (const term of femaleTerms) {
|
||||
if (lowerName.includes(term)) return 'female';
|
||||
}
|
||||
|
||||
// Common male/female voice names
|
||||
if (/(david|james|john|paul|mark|thomas|daniel|jack|william|george|michael|robert|peter|brian|richard|steve|bruce)/i.test(lowerName)) {
|
||||
return 'male';
|
||||
}
|
||||
|
||||
if (/(mary|sarah|emma|susan|julia|karen|lisa|anna|laura|amy|elizabeth|jennifer|maria|emily|jessica|alice|victoria)/i.test(lowerName)) {
|
||||
return 'female';
|
||||
}
|
||||
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set voice options
|
||||
* @param {Object} options - Voice options
|
||||
|
||||
Reference in New Issue
Block a user