feat: add azure TTS

This commit is contained in:
2026-01-13 22:03:10 -03:00
parent c96ba7e63d
commit f87171590e
3 changed files with 396 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
import { TTSModule, TTSResponse } from "../tts";
import { VoicesManager, Communicate } from 'edge-tts-universal';
class AzureTTS implements TTSModule {
private voices: Array<string> | undefined = undefined;
name = "Azure";
async getVoices(): Promise<Array<string> | undefined> {
if (!this.voices) {
const voiceMgr = await VoicesManager.create();
const voiceQuery = await voiceMgr.find({});
this.voices = voiceQuery.map((voice) => voice.ShortName);
}
return this.voices;
};
async generate(voice: string, text: string): Promise<TTSResponse> {
const comm = new Communicate(text, {
voice: voice
});
const buffers: Buffer[] = [];
for await (const chunk of comm.stream()) {
if (chunk.type === 'audio' && chunk.data) {
buffers.push(chunk.data);
}
}
return { data: Buffer.concat(buffers) };
};
}
export default new AzureTTS();