Convert text to natural-sounding speech in Arabic, French, and English.
Text-to-Speech (TTS) generates spoken audio from text. OpenDunes supports Arabic including Modern Standard Arabic and Darija-inflected voices, making it suitable for voice assistants, IVR systems, and accessibility features targeting Algerian users.
import os
from openai import OpenAI
from pathlib import Path
client = OpenAI(
base_url="https://opendunes.com/v1",
api_key=os.environ["OPENDUNES_API_KEY"],
)
resp = client.audio.speech.create(
model="x-ai/grok-voice-tts-1.0",
voice="nova",
input="مرحباً! أهلاً بك في OpenDunes، بوابتك إلى أكثر من مئتي نموذج ذكاء اصطناعي.",
)
Path("output.mp3").write_bytes(resp.content)For longer texts, stream directly to disk to avoid buffering the full response in memory:
with client.audio.speech.with_streaming_response.create(
model="x-ai/grok-voice-tts-1.0",
voice="alloy",
input="OpenDunes routes your requests to the best available model and bills you in Algerian Dinars.",
) as response:
response.stream_to_file("output.mp3")| Parameter | Description |
|---|---|
model | A TTS model slug — filter the catalog with ?modality=speech. |
voice | Voice preset name — available voices vary by model. |
input | Text to synthesize (up to the model's character limit). |
response_format | mp3 (default), opus, aac, flac, wav, pcm. |
speed | 0.25–4.0. Default 1.0. |
TTS is billed in DA per character of input text. Rates appear in the model catalog.