//native
type Speechify = {
token: string;
};
/**
* Create access token
* Create a new API token for the logged in user
*/
export async function main(
auth: Speechify,
body: {
grant_type: "client_credentials";
scope?:
| "audio:speech"
| "audio:stream"
| "audio:all"
| "voices:read"
| "voices:create"
| "voices:delete"
| "voices:all";
},
) {
const url = new URL(`https://api.sws.speechify.com/v1/auth/token`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 428 days ago