0

Create audio generation request

by
Published Oct 17, 2025

Generate audio from input text

Script togetherai Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Togetherai = {
3
  api_key: string;
4
};
5
/**
6
 * Create audio generation request
7
 * Generate audio from input text
8
 */
9
export async function main(
10
  auth: Togetherai,
11
  body: {
12
    model: string;
13
    input: string;
14
    voice: string;
15
    response_format?: "mp3" | "wav" | "raw";
16
    language?:
17
      | "en"
18
      | "de"
19
      | "fr"
20
      | "es"
21
      | "hi"
22
      | "it"
23
      | "ja"
24
      | "ko"
25
      | "nl"
26
      | "pl"
27
      | "pt"
28
      | "ru"
29
      | "sv"
30
      | "tr"
31
      | "zh";
32
    response_encoding?: "pcm_f32le" | "pcm_s16le" | "pcm_mulaw" | "pcm_alaw";
33
    sample_rate?: number;
34
    stream?: false | true;
35
  },
36
) {
37
  const url = new URL(`https://api.together.xyz/v1/audio/speech`);
38

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