Results & Response
TTSResult Schema
Every successful synthesis call returns a TTSResult object containing the audio data and metadata.
Fields
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
audio_data | bytes | Raw audio bytes in the requested format. Write directly to a file or stream to a player. |
sample_rate | int | Sample rate in Hz (e.g., 24000 for most formats, 8000 for mulaw/alaw). |
format | string | The output format of the audio (e.g., "mp3", "pcm", "wav"). |
Example
python
from shunyalabs import AsyncShunyaClient, TTSConfig
client = AsyncShunyaClient(api_key="your-api-key")
config = TTSConfig(model="zero-indic", voice="Nisha", response_format="mp3")
result = await client.tts.synthesize("Hello, welcome to Shunya!", config=config)
# Access result fields
print(f"Format: {result.format}") # "mp3"
print(f"Sample rate: {result.sample_rate}") # 24000
print(f"Audio size: {len(result.audio_data)} bytes")
# Save to file
with open("output.mp3", "wb") as f:
f.write(result.audio_data)