Fixed option ui binidngs.

This commit is contained in:
2025-04-05 11:29:30 +00:00
parent b50f60e195
commit 115704f89d
6 changed files with 355 additions and 301 deletions
+52 -28
View File
@@ -177,37 +177,39 @@ class TTSFactoryModule extends BaseModule {
/**
* Initialize a specific TTS handler
* @param {string} id - Handler ID
* @returns {Promise<boolean>} - Success status
* @param {string} id - Handler ID to initialize
* @returns {Promise<boolean>} - Resolves with success status
*/
async initializeHandler(id) {
if (!id || !this.handlers[id]) {
console.error(`TTS Factory: Handler '${id}' not found`);
if (!this.handlers[id]) {
console.error(`TTS Factory: Handler ${id} not found`);
return false;
}
console.log(`TTS Factory: Initializing handler ${id}`);
const progressCallback = (progress, message) => {
const mappedProgress = (progress / 100) || 0;
console.log(`TTS Factory: Handler ${id} progress: ${progress}%, ${message}`);
this.reportProgress(50 + Math.round(mappedProgress * 40), `Initializing ${id}: ${message}`);
};
try {
this.reportProgress(0, `Initializing ${id} TTS handler`);
// Initialize the handler
const success = await this.handlers[id].initialize(
(progress, message) => {
this.reportProgress(progress, message);
}
);
// Update initialization status
// Initialize the handler with progress callback
const success = await this.handlers[id].initialize(progressCallback);
this.initStatus[id] = success;
if (success) {
console.log(`TTS Factory: Successfully initialized ${id} TTS handler`);
console.log(`TTS Factory: Handler ${id} initialized successfully`);
// Force getVoices() to ensure voices are loaded
const voices = this.handlers[id].getVoices();
console.log(`TTS Factory: Handler ${id} has ${voices ? voices.length : 0} voices available after initialization`);
} else {
console.error(`TTS Factory: Failed to initialize ${id} TTS handler`);
console.warn(`TTS Factory: Handler ${id} initialization failed`);
}
return success;
} catch (error) {
console.error(`TTS Factory: Error initializing ${id} TTS handler:`, error);
console.error(`TTS Factory: Error initializing handler ${id}:`, error);
this.initStatus[id] = false;
return false;
}
@@ -229,11 +231,9 @@ class TTSFactoryModule extends BaseModule {
* @returns {boolean} - Success status
*/
setActiveHandler(id) {
// Handle 'none' option specially
// If 'none' is passed, disable TTS
if (id === 'none') {
this.activeHandler = null;
// Update TTS availability state
this.ttsAvailable = false;
// Notify about TTS availability change
@@ -241,10 +241,16 @@ class TTSFactoryModule extends BaseModule {
detail: { available: false }
}));
console.log("TTS Factory: TTS disabled (none selected)");
// Notify about handler change
document.dispatchEvent(new CustomEvent('tts:handlerChanged', {
detail: { handlerId: 'none' }
}));
console.log('TTS Factory: TTS disabled');
return true;
}
// Check if the handler exists
if (!this.handlers[id]) {
console.error(`TTS Factory: Handler not found: ${id}`);
return false;
@@ -265,6 +271,11 @@ class TTSFactoryModule extends BaseModule {
detail: { available: true }
}));
// Notify about handler change
document.dispatchEvent(new CustomEvent('tts:handlerChanged', {
detail: { handlerId: id }
}));
console.log(`TTS Factory: Active handler set to ${id}`);
return true;
}
@@ -366,18 +377,31 @@ class TTSFactoryModule extends BaseModule {
}
/**
* Get available voices for the active TTS handler
* @returns {Array} - Array of voice objects
* Get voices from the active handler
* @returns {Array} - Array of voices
*/
getVoices() {
if (!this.activeHandler) return [];
// Get the active handler
const handler = this.getActiveHandler();
try {
return this.handlers[this.activeHandler].getVoices();
} catch (error) {
console.error("Error getting voices:", error);
// Check if we have an active handler
if (!handler) {
console.log('TTS Factory: No active handler, returning empty voices array');
return [];
}
// Get voices from the active handler
const voices = handler.getVoices();
console.log(`TTS Factory: Retrieved ${voices ? voices.length : 0} voices from ${this.activeHandler}`);
// Check if we have any voices
if (!voices || voices.length === 0) {
console.warn(`TTS Factory: No voices retrieved from ${this.activeHandler} handler`);
return [];
}
// Return voices
return voices;
}
/**