Convert text to natural speech audio via the OpenDunes TTS endpoint.
The text-to-speech endpoint synthesizes audio from text. It is OpenAI-compatible — the openai SDK's audio.speech.create call works with a base URL swap. The response is the raw audio binary.
import OpenAI from "openai";
import { createWriteStream } from "fs";
import { pipeline } from "stream/promises";
const client = new OpenAI({
baseURL: "https://opendunes.com/v1",
apiKey: process.env.OPENDUNES_API_KEY,
});
const mp3 = await client.audio.speech.create({
model: "x-ai/grok-voice-tts-1.0",
voice: "shimmer",
input: "مرحبا! أهلاً وسهلاً في خدمة OpenDunes.",
response_format: "mp3",
speed: 1.0, // 0.25–4.0
});
await pipeline(mp3.body, createWriteStream("./output.mp3"));| Field | Required | Description |
|---|---|---|
model | Yes | A TTS model slug — filter the catalog with ?modality=speech |
input | Yes | The text to synthesize |
voice | Yes | Voice preset name — varies by model |
response_format | No | mp3, pcm, wav, opus, flac, or aac |
speed | No | Playback speed multiplier, 0.25–4.0 (default 1.0) |
TTS is billed in DA per character of input — the character count is known before the call, so the cost is settled deterministically. Rates appear on each model's catalog page.