Update code to typescript

This commit is contained in:
2026-05-14 20:06:15 +02:00
parent fdb4b2d50f
commit f2ce38c176
68 changed files with 7647 additions and 5121 deletions

69
src/tts/registry.ts Normal file
View File

@@ -0,0 +1,69 @@
import type { BaseEngine } from "./BaseEngine.js";
import { AzureEngine } from "./azure.js";
import { ElevenEngine } from "./eleven.js";
import { EspeakEngine } from "./espeak.js";
import { GoogleEngine } from "./google.js";
import { GtranslateEngine } from "./gtranslate.js";
import { OpenAIEngine } from "./openai.js";
import { SamEngine } from "./sam.js";
import { UnrealEngine } from "./unreal.js";
import { WatsonEngine } from "./watson.js";
export class TTSRegistry {
private engines: Record<string, BaseEngine>;
private _announcement: BaseEngine;
private _announcementVoice: string;
constructor(initialAnnouncementEngineName: string, initialAnnouncementVoice: string) {
this.engines = {
azure: new AzureEngine(),
eleven: new ElevenEngine(),
espeak: new EspeakEngine(),
google: new GoogleEngine(),
gtranslate: new GtranslateEngine(),
openai: new OpenAIEngine(),
sam: new SamEngine(),
unreal: new UnrealEngine(),
watson: new WatsonEngine(),
};
for (const name of Object.keys(this.engines)) {
console.log(`Loaded TTS engine: ${name}`);
}
const ann = this.engines[initialAnnouncementEngineName];
if (!ann) {
throw new Error(
`ANNOUNCEMENT_ENGINE "${initialAnnouncementEngineName}" is not a registered TTS engine`,
);
}
this._announcement = ann;
this._announcementVoice = initialAnnouncementVoice;
}
get(name: string): BaseEngine | undefined {
return this.engines[name];
}
has(name: string): boolean {
return name in this.engines;
}
list(): string[] {
return Object.keys(this.engines);
}
get announcement(): BaseEngine {
return this._announcement;
}
set announcement(engine: BaseEngine) {
this._announcement = engine;
}
get announcementVoice(): string {
return this._announcementVoice;
}
set announcementVoice(voice: string) {
this._announcementVoice = voice;
}
}