0

Get stream

by
Published Apr 8, 2025

Gets the stream speech 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 stream
7
 * Gets the stream speech for the given input
8
 */
9
export async function main(
10
  auth: Speechify,
11
  Accept: string,
12
  body: {
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/stream`);
25

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