Skip to main content

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

The REST endpoint authenticates with an 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.
Plug it into an agent:

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.
VoiceToneSuggested use cases
eve (default)Energetic and upbeat
altairElegant, refined, and effortlessly premiumAdvertising, Narration
araWarm and friendly
atlasConfident, commanding, and reassuringSales, Assistant
carinaSoft, empathetic, and soothingWellness, Support
castorCharismatic, down-to-earth, and easygoingSales, Support
celesteCompassionate, confident, and reassuringSupport, Assistant
cosmoBright, curious, and easy to followEducation, Podcast
heliosUpbeat, energetic, and endlessly versatileAssistant, Wellness
helixBold, dynamic, and adrenaline-fueledCommentary, Podcast
irisFriendly, upbeat, and naturally charmingSales, Support
keplerInventive, forward-thinking, and charismaticAdvertising, Podcast
leoAuthoritative and strong
lumenWarm, articulate, and engagingEducation, Advertising
lunaGentle, patient, and deeply nurturingEducation, Assistant
luxGrounded, calm, and quietly wiseWellness, Narration
nakshWarm, thoughtful, and wiseAssistant, Support
orionRich, cinematic, and resonantNarration, Audiobooks
perseusStrong, confident, and trustworthyAdvertising, Narration
rexConfident and clear
rigelPrecise, professional, and calmly confidentAssistant, Support
salSmooth and balanced
siriusQuick-witted, clever, and playfulCommentary, Characters
ursaFriendly, warm, and steadfastAssistant, Podcast
zaganPowerful, dramatic, and unmistakableCharacters, Narration
zenithSharp, focused, and drivenSales, Advertising

Custom voices

Clone a voice from a short reference clip (WAV, ≤120 s) with the custom-voices helper. It returns a voice_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 default codec="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:
codecBest for
mp3General web use — wide compatibility.
wavLossless — editing / post-production.
pcm (default)Raw audio — real-time pipelines.
mulawTelephony (G.711 μ-law).
alawTelephony (G.711 A-law).
Supported sample_rate values: 8000, 16000, 22050, 24000 (xAI’s own default), 44100, 48000.

Rates

xAI bills TTS per character. Patter’s default rate (provider key xai_tts) is **0.015/1kcharacters(0.015 / 1k characters** (15.00 / 1M chars). Override per-project via Patter(pricing={"xai_tts": {"price": ...}}). See Metrics for the full rate table.

Options

PythonTypeScriptDefaultNotes
api_keyapiKeyReads XAI_API_KEY when omitted.
voicevoice"eve"Built-in or custom voice ID (case-insensitive).
languagelanguage"auto"BCP-47 tag or "auto". Required by xAI.
codeccodec"pcm"pcm / mulaw / alaw / wav / mp3.
sample_ratesampleRate160008000 / 16000 / 22050 / 24000 / 44100 / 48000.
speedspeedNoneSpeaking-rate multiplier in [0.7, 1.5].
optimize_streaming_latencyoptimizeStreamingLatencyNone0 / 1 / 2 — higher trades quality for lower time-to-first-audio.
text_normalizationtextNormalizationFalseNormalize numbers / abbreviations / symbols to spoken form.
base_urlbaseUrlxAI /tts endpointOverride for proxying or tests.

Low-level usage

The pipeline-mode wrapper adds XAI_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.