Update TTS providers and story markup
This commit is contained in:
@@ -20,6 +20,7 @@ export class KokoroTTSModule extends TTSHandlerModule {
|
||||
this.lastProgressTime = null;
|
||||
this.lastProgressValue = null;
|
||||
this.modelLoaded = false;
|
||||
this.unsupportedReason = '';
|
||||
|
||||
// Options for playback
|
||||
this.options = {
|
||||
@@ -37,7 +38,8 @@ export class KokoroTTSModule extends TTSHandlerModule {
|
||||
'pause',
|
||||
'resume',
|
||||
'getDefaultVoices',
|
||||
'setVoiceOptions'
|
||||
'setVoiceOptions',
|
||||
'supportsGameLanguage'
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -59,6 +61,18 @@ export class KokoroTTSModule extends TTSHandlerModule {
|
||||
return false;
|
||||
}
|
||||
|
||||
const gameConfig = this.getModule('game-config');
|
||||
const gameLanguage = gameConfig?.getLocale?.() || 'en_US';
|
||||
if (!this.supportsGameLanguage(gameLanguage)) {
|
||||
this.voices = [];
|
||||
this.isReady = false;
|
||||
this.unsupportedReason = `Kokoro TTS supports English and Chinese only; game language is ${gameLanguage}`;
|
||||
this.reportProgress(100, 'Kokoro TTS disabled for this language');
|
||||
console.log(`Kokoro TTS: ${this.unsupportedReason}`);
|
||||
return true;
|
||||
}
|
||||
this.unsupportedReason = '';
|
||||
|
||||
this.addEventListener(document, 'preference-updated', (event) => {
|
||||
const { category, key } = event.detail || {};
|
||||
if (category === 'audio' && ['masterVolume', 'ttsVolume', 'masterVolumeEnabled', 'ttsVolumeEnabled'].includes(key) && this.currentAudio) {
|
||||
@@ -388,12 +402,27 @@ export class KokoroTTSModule extends TTSHandlerModule {
|
||||
|
||||
return Math.max(0, Math.min(1, this.options.volume * (masterEnabled ? masterVolume : 0) * (ttsEnabled ? ttsVolume : 0)));
|
||||
}
|
||||
|
||||
supportsGameLanguage(language) {
|
||||
const normalized = String(language || '').trim().replace('_', '-').toLowerCase();
|
||||
const languageCode = normalized.split('-')[0];
|
||||
return languageCode === 'en'
|
||||
|| languageCode === 'english'
|
||||
|| languageCode === 'zh'
|
||||
|| languageCode === 'chinese'
|
||||
|| languageCode === 'cmn'
|
||||
|| languageCode === 'yue';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available voices
|
||||
* @returns {Array} - Array of voice objects
|
||||
*/
|
||||
async getVoices() {
|
||||
if (this.unsupportedReason) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// If no voices are loaded yet, return default voices
|
||||
if (!this.voices || this.voices.length === 0) {
|
||||
return this.getDefaultVoices();
|
||||
|
||||
Reference in New Issue
Block a user