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 API request 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
ipv4_only = True, #Temporary Fix Until Azure CDN outage is fully fixed
)
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
play=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"))
For integration in servers, make sure save_to is unique for every call and play is set to False. If not calls will fail upon concurrent requests.
The PyPI page includes a similar example and reiterates the need for ffmpeg/ffplay and PortAudio for certain features. (PyPI)
Minimal Websocket example
from snorbyte import Snorbyte # e.g., "from snorbyte import Snorbyte"
import time
API_KEY = "<YOUR-API-KEY>"
def consume_stream(b: bytes):
print(f"chunk {len(b)} bytes")
def main():
client = Snorbyte(api_key=API_KEY)
client.ws_connect()
try:
path1, info1 = client.ws_send(
utterance="ग्रुप प्रोजेक्ट में हर कोई अपना हिस्सा टाइम पर दे दे तो प्रेज़ेंटेशन शाइन करेगी, वरना आख़िरी रात को हड़बड़ी में स्लाइड्स बिगड़ जाती हैं, तो चलो एक शेड्यूल फिक्स करते हैं और डेडलाइन से पहले एक ड्राई-रन करके फीडबैक फ्रीज़ कर देते हैं।",
speaker_id=228,
tone="Encouraging",
speed=1.00,
denoise=False,
fmt="pcm",
save_to="demo_out_1.wav",
stream_bytes_callback=consume_stream,
play=True,
timeout=30, #optional
)
print("[WS] saved:", path1)
print("[WS] metrics:", info1.get("latency_ms", {}))
path1, info1 = client.ws_send(
utterance="ठीक है, फिर शाम को रिपोर्ट भेज दूँगा; आप बस मेट्रिक्स देख लेना और अपना फीडबैक बता देना।",
speaker_id=49,
tone="", # or "Encouraging"/"Consoling" for Charan/Shreeja only
speed=1.00,
denoise=True,
fmt="pcm",
save_to="demo_out_1.mp3",
stream_bytes_callback=consume_stream,
play=True,
)
print("[WS] saved:", path1)
print("[WS] metrics:", info1.get("latency_ms", {}))
path1, info1 = client.ws_send(
utterance="देख भाई, धीरे-धीरे कर ना, फालतू टेंशन मत ले, जो काम समय से हो सकता है, उसे जबरदस्ती धक्का देकर बिगाड़ने से अच्छा है, आराम से कर, रोज़ थोड़ा-थोड़ा बढ़ेगा।",
speaker_id=67,
tone="", # or "Encouraging"/"Consoling" for Charan/Shreeja only
speed=1.00,
denoise=False,
fmt="pcm",
save_to="demo_out_1.wav",
stream_bytes_callback=consume_stream,
play=False,
)
print("[WS] saved:", path1)
print("[WS] metrics:", info1.get("latency_ms", {}))
finally:
time.sleep(2)
client.ws_close()
client.close()
print("[WS] closed")
if __name__ == "__main__":
main()
Parameters (client constructor)
- api_key (str, required) — Your Snorbyte API key.
- endpoint (str, required) — Full URL to the
/ttsendpoint, 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_idorspeaker_name. -
speaker_name (str, optional) — Case-insensitive voice name. Use either
speaker_idorspeaker_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.00normal,1.1slightly faster). (Changing speed, affects latency by a bit) -
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; requiresffplay/ffmpegfor live playback/encoding. (PyPI)
-
stream (bool, optional) — If
True, audio begins arriving immediately; combine withstream_bytes_callbackto 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).
-
play (bool, optional) — If
True, the client will attempt a playback with any sounddevices connected to the machine:- PCM path uses
sounddevice(PortAudio required on Linux). - MP3/WAV path uses
ffplayreading from a pipe. (PyPI)
- PCM path uses
-
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
Nonewhen purely streaming or for large outputs). - info (dict) — Timing/metadata such as
latency_msto help you track first-audio and total times. (Keys may evolve with versions.)
Tips
- For low TTFB, set
stream=Trueand choose a lightweight format for your player. Many pipelines preferfmt="pcm"to avoid decoder startup, or"mp3"for compactness. - Initialize client once and do followup calls with
.tts, make sure to setsave_toto unique andplayto false if you are doing concurrent calls. - Verify
ffmpeg,ffplay, and (if using PCM playback)libportaudio2are installed. (PyPI)