0

Text To 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
 * Text To Speech
7
 *
8
 */
9
export async function main(
10
  auth: Deepinfra,
11
  voice_id: string,
12
  x_deepinfra_source: string,
13
  body: {
14
    text: string;
15
    model_id?: string;
16
    output_format?: "wav";
17
    language_code?: string;
18
  },
19
) {
20
  const url = new URL(
21
    `https://api.deepinfra.com/v1/text-to-speech/${voice_id}`,
22
  );
23

24
  const response = await fetch(url, {
25
    method: "POST",
26
    headers: {
27
      "x-deepinfra-source": x_deepinfra_source,
28
      "Content-Type": "application/json",
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: JSON.stringify(body),
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39