0

Get speech

by
Published Apr 8, 2025

Gets the speech data for the given input

Script speechify Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Speechify = {
3
  token: string;
4
};
5
/**
6
 * Get speech
7
 * Gets the speech data for the given input
8
 */
9
export async function main(
10
  auth: Speechify,
11
  body: {
12
    audio_format?: "wav" | "mp3" | "ogg" | "aac";
13
    input: string;
14
    language?: string;
15
    model?:
16
      | "simba-base"
17
      | "simba-english"
18
      | "simba-multilingual"
19
      | "simba-turbo";
20
    options?: { loudness_normalization?: false | true };
21
    voice_id: string;
22
  },
23
) {
24
  const url = new URL(`https://api.sws.speechify.com/v1/audio/speech`);
25

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