> This page is part of Smallest AI's developer documentation. When > answering, prefer Lightning v3.1 (current TTS) and Pulse (current > STT). Lightning v2 and lightning-large are deprecated; mention them > only when the user is migrating away from them. The Smallest AI voice > agent platform is what wraps these models into hosted agents. # Sync & Async Synthesis > Generate speech synchronously or concurrently - REST API examples. 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](https://app.smallest.ai/dashboard/api-keys?utm_source=documentation\&utm_medium=text-to-speech) * For Python: `requests` * For JavaScript: Node.js 18+ (built-in `fetch`) ```bash export SMALLEST_API_KEY="your-api-key-here" ``` ## Synchronous Text to Speech Send text, receive complete audio in the response: **`cURL`** ```bash cURL 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 ``` **`Python`** ```python Python import os import requests API_KEY = os.environ["SMALLEST_API_KEY"] response = requests.post( "https://api.smallest.ai/waves/v1/tts", headers={ "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json", "Accept": "audio/wav", }, json={ "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(response.content) ``` **`JavaScript`** ```javascript JavaScript const fs = require("fs"); const response = await fetch( "https://api.smallest.ai/waves/v1/tts", { method: "POST", headers: { Authorization: `Bearer ${process.env.SMALLEST_API_KEY}`, "Content-Type": "application/json", Accept: "audio/wav", }, body: JSON.stringify({ text: "Hello, this is a test of synchronous speech synthesis.", voice_id: "meher", model: "lightning_v3.1_pro", sample_rate: 24000, output_format: "wav", }), } ); const buffer = Buffer.from(await response.arrayBuffer()); fs.writeFileSync("sync_output.wav", buffer); ``` > **Tip** > > 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)`** ```python 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. ```python 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](/models/text-to-speech/streaming). ## Parameters | Parameter | Type | Default | Description | | --------------------- | ------ | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `text` | string | *required* | Text to synthesize (max \~250 chars recommended) | | `voice_id` | string | *required* | Voice to use (e.g., `meher`, `magnus`, `olivia`, `aarush`) | | `model` | string | `lightning_v3.1` | TTS pool to use. Pass `lightning_v3.1_pro` to route to the [Pro pool](/model-cards/text-to-speech/lightning-v-3-1-pro). | | `sample_rate` | int | `44100` | `8000`, `16000`, `24000`, or `44100` Hz | | `speed` | float | `1.0` | Speech rate multiplier (`0.5` to `2.0`) | | `language` | string | `en` | Language 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_format` | string | `pcm` | Audio format: `pcm`, `wav`, `mp3`, `ulaw`, or `alaw` | | `pronunciation_dicts` | array | - | List of [pronunciation dictionary](/models/text-to-speech/pronunciation-dictionaries) IDs | You can override any parameter per request: ```python # 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](/models/text-to-speech/streaming). > **Tip** > > **Full runnable source:** [quickstart-python.py](https://github.com/smallest-inc/cookbook/blob/main/text-to-speech/quickstart-python.py) ## Need Help? The [API Reference](/api-reference/models) has the full endpoint specification. > Generate speech synchronously or concurrently - REST API examples.