import { fetch } from "https://esm.town/v/std/fetch";
import process from "node:process";
export const elevenlabsTTS = async (req, res) => {
const payload = {
text: req.query.text,
model_id: "eleven_monolingual_v1",
voice_settings: {
stability: 0.5,
similarity_boost: 0.5,
},
};
const voiceId = "21m00Tcm4TlvDq8ikWAM";
const audio = await fetch(
`https://api.elevenlabs.io/v1/text-to-speech/${voiceId}`,
{
method: "POST",
headers: {
"Accept": "audio/mpeg",
"xi-api-key": process.env.ELEVENLABS_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
},
);
res.set("Content-Type", "audio/mpeg");
res.send(audio);
};