Skip to navigation

Sync & Async Synthesis

Generate speech synchronously or concurrently - REST API examples.
View as Markdown

Generate speech via the REST API - synchronously (one request, complete audio) or asynchronously (multiple requests in parallel).

Sample output (sync, voice: meher, model: lightning_v3.1_pro):

Requirements

  • An API key from the Smallest AI Console
  • For Python: requests
  • For JavaScript: Node.js 18+ (built-in fetch)
export SMALLEST_API_KEY="your-api-key-here"

Synchronous Text to Speech

Send text, receive complete audio in the response:

curl -X POST "https://api.smallest.ai/waves/v1/tts" \
-H "Authorization: Bearer $SMALLEST_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: audio/wav" \
-d '{
"text": "Hello, this is a test of synchronous speech synthesis.",
"voice_id": "meher",
"model": "lightning_v3.1_pro",
"sample_rate": 24000,
"output_format": "wav"
}' --output sync_output.wav

Drop the model field (or set it to "lightning_v3.1") to use the standard Lightning v3.1 pool - that pool has more voices, the full 12-language catalog, plus voice cloning. The unified /waves/v1/tts route serves both.

Asynchronous Text to Speech

For concurrent requests (e.g., generating multiple audio files in parallel):

Python (asyncio)
import os
import asyncio
import aiohttp
API_KEY = os.environ["SMALLEST_API_KEY"]
URL = "https://api.smallest.ai/waves/v1/tts"
async def synthesize(session, text, filename):
async with session.post(URL, headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Accept": "audio/wav",
}, json={
"text": text,
"voice_id": "meher",
"model": "lightning_v3.1_pro",
"sample_rate": 24000,
"output_format": "wav",
}) as resp:
audio = await resp.read()
with open(filename, "wb") as f:
f.write(audio)
print(f"Saved {filename}")
async def main():
async with aiohttp.ClientSession() as session:
await asyncio.gather(
synthesize(session, "First sentence.", "async_1.wav"),
synthesize(session, "Second sentence.", "async_2.wav"),
synthesize(session, "Third sentence.", "async_3.wav"),
)
asyncio.run(main())

Python SDK

The smallestai Python SDK wraps the same endpoint. client.waves.synthesize_tts returns audio byte chunks; join them to get the full file. AsyncSmallestAI provides the same methods for async code.

from smallestai import SmallestAI
client = SmallestAI() # reads SMALLEST_API_KEY from the environment
audio = b"".join(client.waves.synthesize_tts(
text="Hello, this is a test of synchronous speech synthesis.",
voice_id="meher",
model="lightning_v3.1_pro",
sample_rate=24000,
output_format="wav",
))
with open("sync_output.wav", "wb") as f:
f.write(audio)

For streaming synthesis via WebSocket or SSE, see Streaming TTS.

Parameters

ParameterTypeDefaultDescription
textstringrequiredText to synthesize (max ~250 chars recommended)
voice_idstringrequiredVoice to use (e.g., meher, magnus, olivia, aarush)
modelstringlightning_v3.1TTS pool to use. Pass lightning_v3.1_pro to route to the Pro pool.
sample_rateint441008000, 16000, 24000, or 44100 Hz
speedfloat1.0Speech rate multiplier (0.5 to 2.0)
languagestringenLanguage code matching the voice. Indian: en, hi, mr, kn, ta, bn, gu, te, ml, pa, or. European: es. Each voice supports a subset - see voice tags via GET /waves/v1/lightning-v3.1/get_voices.
output_formatstringpcmAudio format: pcm, wav, mp3, ulaw, or alaw
pronunciation_dictsarray-List of pronunciation dictionary IDs

You can override any parameter per request:

# ci:skip — fragment; assumes URL/headers/requests from the synchronous example above
# Override speed and sample rate for a single call
response = requests.post(URL, headers=headers, json={
"text": "Fast and high quality.",
"voice_id": "magnus",
"speed": 1.5,
"sample_rate": 44100,
"output_format": "mp3",
})

When to Use Each Mode

  • Synchronous: Real-time voice assistants, chatbot responses, single audio generation
  • Asynchronous: Batch processing, generating multiple audio files, audiobook chapters, concurrent API calls

For real-time streaming where audio starts playing before generation completes, see Streaming TTS.

Full runnable source: quickstart-python.py

Need Help?

The API Reference has the full endpoint specification.