import { TTSModule, TTSResponse } from '../tts'; import { VoicesManager, Communicate } from 'edge-tts-universal'; class AzureTTS implements TTSModule { private voices: Array | undefined = undefined; public name: string = 'Azure'; async getVoices(): Promise | 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 { 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();