from supertone import SupertoneVOICE_ID = "20160a4c5ba38967330c84" # replace with your voice IDwith Supertone(api_key=API_KEY) as client: response = client.text_to_speech.stream_speech( voice_id=VOICE_ID, text="This response is streamed chunk by chunk.", language="en", model="sona_speech_1", output_format="wav", ) with open("streamed.wav", "wb") as f: for chunk in response.result.iter_bytes(): f.write(chunk)
import asynciofrom supertone import SupertoneVOICE_ID = "20160a4c5ba38967330c84" # replace with your voice IDasync def main(): async with Supertone(api_key=API_KEY) as client: response = await client.text_to_speech.stream_speech_async( voice_id=VOICE_ID, text="This response is streamed chunk by chunk.", language="en", model="sona_speech_1", ) with open("streamed.wav", "wb") as f: async for chunk in response.result.aiter_bytes(): f.write(chunk)asyncio.run(main())
import { Supertone } from "@supertone/supertone";import * as fs from "node:fs";const VOICE_ID = "20160a4c5ba38967330c84"; // replace with your voice IDconst client = new Supertone({ apiKey: API_KEY });const response = await client.textToSpeech.streamSpeech({ voiceId: VOICE_ID, apiConvertTextToSpeechUsingCharacterRequest: { text: "This response is streamed chunk by chunk.", language: "en", model: "sona_speech_1", outputFormat: "wav", },});if (response.result && typeof response.result === "object" && "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("streamed.wav", Buffer.concat(chunks));}