coquiLocal.ts 637 B

123456789101112131415161718192021222324252627282930
  1. import { TTSBackend } from "@/types/backend";
  2. export async function coquiLocal(
  3. config: TTSBackend["coquiLocal"],
  4. message: string,
  5. ) {
  6. const voiceId = config?.coquiLocal_voiceid;
  7. if (!voiceId) {
  8. throw new Error("Invalid CoquiLocal TTS Voice Id");
  9. }
  10. try {
  11. const res = await fetch(`${config.coquiLocal_url}/api/tts`, {
  12. method: 'POST',
  13. headers: {
  14. 'text': message,
  15. 'speaker-id': config.coquiLocal_voiceid,
  16. }
  17. });
  18. const data = await res.arrayBuffer()
  19. return { audio: data };
  20. } catch (error) {
  21. console.error('Error in coquiLocal:', error);
  22. throw error;
  23. }
  24. }