0

Openai Audio Speech

by
Published Oct 17, 2025
Script deep_infra Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Deepinfra = {
3
  token: string;
4
};
5
/**
6
 * Openai Audio Speech
7
 *
8
 */
9
export async function main(
10
  auth: Deepinfra,
11
  x_deepinfra_source: string,
12
  body: {
13
    model: string;
14
    input: string;
15
    voice?:
16
      | "luna"
17
      | "aura"
18
      | "quartz"
19
      | "af"
20
      | "af_bella"
21
      | "af_sarah"
22
      | "am_adam"
23
      | "am_michael"
24
      | "bf_emma"
25
      | "bf_isabella"
26
      | "bm_george"
27
      | "bm_lewis"
28
      | "af_nicole"
29
      | "af_sky";
30
    response_format?: "wav";
31
    speed?: number;
32
  },
33
) {
34
  const url = new URL(`https://api.deepinfra.com/v1/openai/audio/speech`);
35

36
  const response = await fetch(url, {
37
    method: "POST",
38
    headers: {
39
      "x-deepinfra-source": x_deepinfra_source,
40
      "Content-Type": "application/json",
41
      Authorization: "Bearer " + auth.token,
42
    },
43
    body: JSON.stringify(body),
44
  });
45
  if (!response.ok) {
46
    const text = await response.text();
47
    throw new Error(`${response.status} ${text}`);
48
  }
49
  return await response.json();
50
}
51