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.
Programmatic access
The table above is also available in code asXAI_VOICES, along with is_xai_builtin_voice for telling a built-in id apart from a custom cloned one (both are case-insensitive), and the xai() / xai_asr() helpers for building a pipeline-mode TTSConfig / STTConfig:
Python
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:
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 keyxai_tts) is **15.00 / 1M chars). Override per-project via Patter(pricing={"xai_tts": {"price": ...}}). See Metrics for the full rate table.
Options
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.

