//native
type Togetherai = {
api_key: string;
};
/**
* Create audio generation request
* Generate audio from input text
*/
export async function main(
auth: Togetherai,
body: {
model: string;
input: string;
voice: string;
response_format?: "mp3" | "wav" | "raw";
language?:
| "en"
| "de"
| "fr"
| "es"
| "hi"
| "it"
| "ja"
| "ko"
| "nl"
| "pl"
| "pt"
| "ru"
| "sv"
| "tr"
| "zh";
response_encoding?: "pcm_f32le" | "pcm_s16le" | "pcm_mulaw" | "pcm_alaw";
sample_rate?: number;
stream?: false | true;
},
) {
const url = new URL(`https://api.together.xyz/v1/audio/speech`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.api_key,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 235 days ago