type Openai = {
api_key: string;
organization_id: string;
};
/**
* Create speech
* Generates audio from the input text.
*/
export async function main(
auth: Openai,
body: {
model: string | ("tts-1" | "tts-1-hd");
input: string;
voice: "alloy" | "echo" | "fable" | "onyx" | "nova" | "shimmer";
response_format?: "mp3" | "opus" | "aac" | "flac" | "wav" | "pcm";
speed?: number;
}
) {
const url = new URL(`https://api.openai.com/v1/audio/speech`);
const response = await fetch(url, {
method: "POST",
headers: {
"OpenAI-Organization": auth.organization_id,
"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 261 days ago
type Openai = {
api_key: string;
organization_id: string;
};
/**
* Create speech
* Generates audio from the input text.
*/
export async function main(
auth: Openai,
body: {
model: string | ("tts-1" | "tts-1-hd");
input: string;
voice: "alloy" | "echo" | "fable" | "onyx" | "nova" | "shimmer";
response_format?: "mp3" | "opus" | "aac" | "flac";
speed?: number;
}
) {
const url = new URL(`https://api.openai.com/v1/audio/speech`);
const response = await fetch(url, {
method: "POST",
headers: {
"OpenAI-Organization": auth.organization_id,
"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 357 days ago