import osfrom supertone import SupertoneVOICE_ID = "20160a4c5ba38967330c84" # replace with your voice IDLONG_TEXT = ( "Once upon a time, in a faraway land, there lived a quiet librarian " "who collected stories of forgotten kingdoms. Every evening she would " "open a leather-bound notebook and continue writing the next chapter " "of a tale she had been telling herself for years. ...continue with " "many more sentences spanning over 300 characters...")with Supertone(api_key=os.environ["SUPERTONE_API_KEY"]) as client: response = client.text_to_speech.create_speech( voice_id=VOICE_ID, text=LONG_TEXT, language="en", ) with open("narration.wav", "wb") as f: f.write(response.result.read())
import { Supertone } from "@supertone/supertone";import * as fs from "node:fs";const VOICE_ID = "20160a4c5ba38967330c84"; // replace with your voice IDconst LONG_TEXT = ` Once upon a time, in a faraway land, there lived a quiet librarian who collected stories of forgotten kingdoms. Every evening she would open a leather-bound notebook and continue writing the next chapter of a tale she had been telling herself for years. ...continue with many more sentences spanning over 300 characters...`.trim();const client = new Supertone({ apiKey: process.env.SUPERTONE_API_KEY });const response = await client.textToSpeech.createSpeech({ voiceId: VOICE_ID, apiConvertTextToSpeechUsingCharacterRequest: { text: LONG_TEXT, language: "en", },});if (response.result instanceof Uint8Array) { fs.writeFileSync("narration.wav", response.result);} else if (response.result && "getReader" in response.result) { const reader = (response.result as ReadableStream<Uint8Array>).getReader(); const chunks: Uint8Array[] = []; while (true) { const { done, value } = await reader.read(); if (done) break; if (value) chunks.push(value); } fs.writeFileSync("narration.wav", Buffer.concat(chunks));}