Refactored modules and updated loader.

This commit is contained in:
2025-04-06 18:35:04 +00:00
parent fc693ae695
commit 0ab639fd25
37 changed files with 3530 additions and 5989 deletions
+16 -25
View File
@@ -6,7 +6,7 @@ import { ApiTTSModuleBase } from './api-tts-module-base.js';
export class OpenAITTSModule extends ApiTTSModuleBase {
constructor() {
super('openai', 'OpenAI TTS');
super('openai-tts', 'OpenAI TTS');
// Voice options specific to OpenAI
this.voiceOptions = {
@@ -115,10 +115,7 @@ export class OpenAITTSModule extends ApiTTSModuleBase {
const langCode = locale.split('-')[0].toLowerCase();
// All OpenAI voices are English-based
// For English locales, we could customize the voice selection
// For non-English locales, we'll just use the default
// In this simple implementation, we'll just use the default voice
// Return default voice
return this.selectDefaultVoice();
}
@@ -127,21 +124,26 @@ export class OpenAITTSModule extends ApiTTSModuleBase {
* @returns {boolean} - Success status
*/
selectDefaultVoice() {
this.voiceOptions.voice = 'alloy';
this.voiceOptions.voice = 'alloy'; // Default voice
return true;
}
/**
* Get available voices
* @returns {Array} - Array of voice objects
*/
getAvailableVoices() {
return this.voices;
}
/**
* Generate speech audio data using OpenAI API
* @param {string} text - Text to generate speech for
* @returns {Promise<Object>} - Audio data object
*/
async generateSpeechAudio(text) {
if (!text || !this.apiKey) {
return {
success: false,
reason: 'missing_api_key_or_text'
};
if (!this.isReady || !this.apiKey) {
return { success: false, reason: 'not_ready' };
}
try {
@@ -239,17 +241,6 @@ export class OpenAITTSModule extends ApiTTSModuleBase {
}
}
// Register the module with the module registry
// Module registry MUST be accessed via window, not direct import
if (window.moduleRegistry) {
try {
// Create instance first, then register it
const openAITTSModule = new OpenAITTSModule();
window.moduleRegistry.register(openAITTSModule);
console.log('OpenAI TTS Module registered successfully');
} catch (err) {
console.error('Failed to register OpenAI TTS Module:', err);
}
} else {
console.error('Module registry not available when attempting to register OpenAI TTS Module');
}
const openAITTSModule = new OpenAITTSModule();
export { openAITTSModule };