Skip to main content
POST
https://api.naga.ac
/
v1
/
audio
/
speech
Speech (TTS)
curl --request POST \
  --url https://api.naga.ac/v1/audio/speech \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "<string>",
  "input": "<string>",
  "voice": "<string>",
  "speed": 123,
  "instructions": "<string>",
  "response_format": "<string>"
}
'

Request Parameters

model
string
required
Target TTS model ID (e.g., gpt-4o-mini-tts).
input
string
required
The text to synthesize (max 32768 characters).
voice
string
required
Voice preset name (e.g., alloy).
speed
number
Playback speed multiplier (> 0).
instructions
string
Additional synthesis hints.
response_format
string
The format for the audio output. Supported formats: mp3, opus, aac, flac, wav, and pcm. If omitted, the format is determined by the provider.

Example Request

from openai import OpenAI
from pathlib import Path

client = OpenAI(
    base_url="https://api.naga.ac/v1",
    api_key="YOUR_API_KEY",
)

speech_file_path = Path("speech.mp3")
resp = client.audio.speech.create(
    model="gpt-4o-mini-tts",
    voice="alloy",  # type: ignore
    input="Hello from NagaAI Text-to-Speech!",
)
resp.stream_to_file(speech_file_path)

Streaming Example

The Speech API supports real-time audio streaming via chunk transfer encoding. This allows audio to be played back as it is being generated, without needing to wait for the entire file to be completed.
import asyncio

from openai import AsyncOpenAI
from openai.helpers import LocalAudioPlayer

client = AsyncOpenAI(
    base_url="https://api.naga.ac/v1",
    api_key="YOUR_API_KEY",
)

async def main() -> None:
    async with client.audio.speech.with_streaming_response.create(
        model="gpt-4o-mini-tts",
        voice="coral",
        input="Today is a wonderful day to build something people love!",
        instructions="Speak in a cheerful and positive tone.",
        response_format="wav",
    ) as response:
        await LocalAudioPlayer().play(response)

if __name__ == "__main__":
    asyncio.run(main())

Response

Binary audio is returned. With SDKs, use helpers to persist the stream. With cURL, pass --output file.ext to save.

Response Fields

The response is a binary audio file stream. The format is determined by the response_format parameter. If this parameter is omitted, the provider selects the default format. Supported formats include:
  • mp3
  • opus
  • aac
  • flac
  • wav
  • pcm
Use SDK stream helpers or save directly to a file using --output flag with cURL.