xAI TTS
XaiTTS targets xAI’s one-shot Text-to-Speech endpoint (POST https://api.x.ai/v1/tts). The response body is raw audio bytes in the requested codec, which maps cleanly onto Patter’s streaming synthesis contract and keeps the provider dependency-free (just aiohttp / fetch).
The default voice is eve, and the default output is PCM-16-LE @ 16 kHz so chunks drop straight into the Patter pipeline without transcoding. For phone calls the carrier factories emit telephony-native audio — see Telephony.
Beta. The adapter is validated against the xAI TTS API spec; it has not yet
been exercised against a live phone call.
Install
Authentication
Authorization: Bearer <key> header. XAI_API_KEY is read automatically when api_key / apiKey is omitted.
Usage
Use the namespaced import (
getpatter.tts.xai) or the flat re-export
(XaiTTS). Both auto-resolve XAI_API_KEY from the environment when
api_key is omitted.Voices
xAI ships a roster of 26 built-in voices, each with a distinct personality.eve is the default; voice IDs are case-insensitive (eve, Eve, and EVE all work). Tone and suggested use cases below are from the xAI Voice Overview; preview samples for each voice in the xAI console playground.
| Voice | Tone | Suggested use cases |
|---|---|---|
eve (default) | Energetic and upbeat | — |
altair | Elegant, refined, and effortlessly premium | Advertising, Narration |
ara | Warm and friendly | — |
atlas | Confident, commanding, and reassuring | Sales, Assistant |
carina | Soft, empathetic, and soothing | Wellness, Support |
castor | Charismatic, down-to-earth, and easygoing | Sales, Support |
celeste | Compassionate, confident, and reassuring | Support, Assistant |
cosmo | Bright, curious, and easy to follow | Education, Podcast |
helios | Upbeat, energetic, and endlessly versatile | Assistant, Wellness |
helix | Bold, dynamic, and adrenaline-fueled | Commentary, Podcast |
iris | Friendly, upbeat, and naturally charming | Sales, Support |
kepler | Inventive, forward-thinking, and charismatic | Advertising, Podcast |
leo | Authoritative and strong | — |
lumen | Warm, articulate, and engaging | Education, Advertising |
luna | Gentle, patient, and deeply nurturing | Education, Assistant |
lux | Grounded, calm, and quietly wise | Wellness, Narration |
naksh | Warm, thoughtful, and wise | Assistant, Support |
orion | Rich, cinematic, and resonant | Narration, Audiobooks |
perseus | Strong, confident, and trustworthy | Advertising, Narration |
rex | Confident and clear | — |
rigel | Precise, professional, and calmly confident | Assistant, Support |
sal | Smooth and balanced | — |
sirius | Quick-witted, clever, and playful | Commentary, Characters |
ursa | Friendly, warm, and steadfast | Assistant, Podcast |
zagan | Powerful, dramatic, and unmistakable | Characters, Narration |
zenith | Sharp, focused, and driven | Sales, Advertising |
Custom voices
Clone a voice from a short reference clip (WAV, ≤120 s) with the custom-voices helper. It returns avoice_id usable as the voice on both XaiTTS and the xAI Realtime engine:
Language
language is required by xAI and defaults to "auto" (the model detects the language of the text). Pass a BCP-47 code — e.g. "en", "it", "pt-BR" — for consistent results. Language validation is case-insensitive.
Speech tags
xAI supports inline speech tags embedded in the synthesized text for expressive delivery — for example[pause] and [laugh] for vocal expressions, plus wrapping tags to change delivery style (whispering, singing). Because Patter forwards the reply text verbatim to xAI, any tags your LLM (or system prompt) produces in the text are honored:
A single request accepts up to 15,000 characters. The adapter warns and
forwards the text as-is past that limit (the API rejects it); split long text
upstream — the pipeline already synthesizes per utterance.
Telephony
The constructor defaultcodec="pcm" @ sample_rate=16000 is correct for web playback and 16 kHz pipelines. For real phone calls use the carrier factories, which negotiate the carrier-native codec so the pipeline skips resampling:
for_twilio() emits G.711 μ-law @ 8 kHz — exactly Twilio’s wire codec, which xAI supports natively — so the audio passes straight through with zero resampling and zero PCM → μ-law encoding.
Output formats
Control the codec and sample rate directly when not using the carrier factories:codec | Best for |
|---|---|
mp3 | General web use — wide compatibility. |
wav | Lossless — editing / post-production. |
pcm (default) | Raw audio — real-time pipelines. |
mulaw | Telephony (G.711 μ-law). |
alaw | Telephony (G.711 A-law). |
sample_rate values: 8000, 16000, 22050, 24000 (xAI’s own default), 44100, 48000.
Rates
xAI bills TTS per character. Patter’s default rate (provider keyxai_tts) is **15.00 / 1M chars). Override per-project via Patter(pricing={"xai_tts": {"price": ...}}). See Metrics for the full rate table.
Options
| Python | TypeScript | Default | Notes |
|---|---|---|---|
api_key | apiKey | — | Reads XAI_API_KEY when omitted. |
voice | voice | "eve" | Built-in or custom voice ID (case-insensitive). |
language | language | "auto" | BCP-47 tag or "auto". Required by xAI. |
codec | codec | "pcm" | pcm / mulaw / alaw / wav / mp3. |
sample_rate | sampleRate | 16000 | 8000 / 16000 / 22050 / 24000 / 44100 / 48000. |
speed | speed | None | Speaking-rate multiplier in [0.7, 1.5]. |
optimize_streaming_latency | optimizeStreamingLatency | None | 0 / 1 / 2 — higher trades quality for lower time-to-first-audio. |
text_normalization | textNormalization | False | Normalize numbers / abbreviations / symbols to spoken form. |
base_url | baseUrl | xAI /tts endpoint | Override for proxying or tests. |
Low-level usage
The pipeline-mode wrapper addsXAI_API_KEY resolution on top of the underlying provider. To use it directly, import from getpatter.providers.xai_tts:
What’s Next
TTS
All TTS providers side by side.
xAI STT
Grok speech-to-text.
xAI Realtime
Grok Voice Agent engine.
Metrics
Cost tracking and rates.

