Refactored modules and updated loader.
This commit is contained in:
@@ -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 };
|
||||
Reference in New Issue
Block a user