Skip to main content

Snorbyte TTS — Python Client

Install

pip install -U snorbyte

Requires Python ≥ 3.9. For compressed live playback/encoding, you need ffmpeg/ffplay on PATH; for PCM playback the package uses sounddevice, which needs PortAudio (installable via your OS package manager). (PyPI)

Windows (ffmpeg/ffplay): (PyPI)

winget install -e --id Gyan.FFmpeg
# or: choco install ffmpeg

Then ensure ffmpeg / ffplay work in a fresh terminal.

Ubuntu/Debian (ffmpeg + PortAudio for PCM playback): (PyPI)

sudo apt-get update
sudo apt-get install -y ffmpeg libportaudio2

Minimal example

from snorbyte import Snorbyte

def consume_stream(b: bytes):
# b are raw audio bytes:
# - fmt="pcm": 16-bit PCM frames (aligned)
# - fmt="mp3"/"wav": compressed chunks
print(f"chunk {len(b)} bytes")

client = Snorbyte(
api_key="YOUR_API_KEY", # required
endpoint="https://api.snorbyte.com/tts" # full /tts URL
)

path, data, info = client.tts(
utterance="दोस्त, दिल टूटा है तो क्या, रात भर प्लेलिस्ट रोएगी...",
speaker_id=49, # or use speaker_name (case-insensitive)
speaker_name="",
tone="", # if supported by the voice
speed=1.00, # float, playback speed factor, adds some latency
denoise=True, # bool, noise suppression
stream=True, # bool, enables streaming for low TTFB
stream_bytes_callback=consume_stream, # optional: handle chunks as they arrive
fmt="pcm", # "pcm" | "mp3" | "wav"
save_to="out.mp3", # optional; auto-names if omitted
playback=True, # if True, play audio while stream is True
# Advanced (optional):
# temperature=0.0, top_p=1.0, repetition_penalty=1.05, chunk_size=8192
)

print("Saved to:", path) # str path to saved file
print("Bytes in memory:", len(data) if data else None) # may be None in pure streaming
print("Info (ms):", info.get("latency_ms"))

The PyPI page includes a similar example and reiterates the need for ffmpeg/ffplay and PortAudio for certain features. (PyPI)


Parameters (client constructor)

  • api_key (str, required) — Your Snorbyte API key.
  • endpoint (str, required) — Full URL to the /tts endpoint, e.g. https://api.snorbyte.com/tts.

Parameters (client.tts(...))

  • utterance (str, required) — The text to synthesize. Use plain Unicode; the client handles sending to the server.

  • speaker_id (str|int, optional) — Numeric voice id. Use either speaker_id or speaker_name.

  • speaker_name (str, optional) — Case-insensitive voice name. Use either speaker_id or speaker_name.

  • tone (str, optional) — Style value if supported by the voice (e.g., "Encouraging"). Leave "" if not applicable.

  • speed (float, optional) — Playback speed factor (e.g., 1.00 normal, 1.1 slightly faster).

  • denoise (bool, optional) — Apply denoising on output if available.

  • fmt (str, optional) — Output format: "mp3", "wav", or "pcm".

    • "pcm": returns raw S16LE frames in the stream callback (low-latency path).
    • "mp3"/"wav": returns compressed chunks; requires ffplay/ffmpeg for live playback/encoding. (PyPI)
  • stream (bool, optional) — If True, audio begins arriving immediately; combine with stream_bytes_callback to process as it streams.

  • stream_bytes_callback (callable, optional) — Called for each chunk of bytes; ideal for piping to your own player, encoder, or WebSocket.

  • save_to (str|Path, optional) — Save the final audio to this path. If omitted, the client can auto-name (depends on format and implementation).

  • playback (bool, optional) — If True, the client will attempt low-latency playback:

    • PCM path uses sounddevice (PortAudio required on Linux).
    • MP3/WAV path uses ffplay reading from a pipe. (PyPI)
  • temperature, top_p, repetition_penalty (floats, optional) — Model sampling controls (tune quality/variability; may affect latency).

  • chunk_size (int, optional) — Stream read block size in bytes (useful to tune smoothness vs syscall overhead). (PyPI)


Return values

path, data, info = client.tts(...)

  • path (str) — Where the file was saved (if saving).
  • data (bytes|None) — Entire audio in memory (may be None when purely streaming or for large outputs).
  • info (dict) — Timing/metadata such as latency_ms to help you track first-audio and total times. (Keys may evolve with versions.)

Tips

  • For ultra-low TTFB, set stream=True and choose a lightweight format for your player. Many pipelines prefer fmt="pcm" to avoid decoder startup, or "mp3" for compactness.
  • Verify ffmpeg, ffplay, and (if using PCM playback) libportaudio2 are installed. (PyPI)