Streaming

Streaming

For real-time playback, stream the audio as it is generated instead of waiting for the full file.

Python (OpenAI SDK)

from openai import OpenAI
 
client = OpenAI(base_url="https://platform.kenpathlabs.com/v1", api_key="YOUR_KEY")
 
with client.audio.speech.with_streaming_response.create(
    model="svara-tts-v1",
    voice="tara",
    input="Streaming audio arrives chunk by chunk.",
    response_format="opus",
) as response:
    for chunk in response.iter_bytes():
        ...  # feed chunk to your player

Fetch (browser/edge)

const res = await fetch("https://platform.kenpathlabs.com/v1/audio/speech", {
  method: "POST",
  headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
  body: JSON.stringify({ model: "svara-tts-v1", voice: "tara", input: text, response_format: "opus" }),
});
const reader = res.body.getReader();
// pipe reader chunks into a MediaSource / WebAudio buffer

Use a low-latency format like opus_48000_64 or pcm_24000 for streaming.