Overview
XAISTTService provides real-time speech-to-text transcription using xAI’s WebSocket STT API with support for interim results, configurable endpointing, multichannel audio, and speaker diarization.
The service streams raw audio (PCM, μ-law, or A-law) to xAI’s endpoint and emits interim and final transcription frames based on the server’s is_final and speech_final flags. The connection is persistent: audio is streamed continuously and the server automatically detects utterance boundaries.
xAI STT API Reference
Pipecat’s API methods for xAI STT integration
Example Implementation
Complete transcription example with xAI STT
Voice Agent Example
Full voice agent with xAI STT, LLM, and TTS
xAI Documentation
Official xAI voice API documentation
Installation
To use xAI STT services, install the required dependencies:Prerequisites
xAI Account Setup
Before using xAI STT services, you need:- xAI Account: Sign up at xAI
- API Key: Generate an API key from your account dashboard
- Language Selection: Choose from 16 supported languages
Required Environment Variables
XAI_API_KEY: Your xAI API key for authentication
Configuration
XAISTTService
xAI API key for authentication (used as Bearer token for the WebSocket
handshake).
WebSocket endpoint URL for xAI STT.
Audio sample rate in Hz. Supported values: 8000, 16000, 22050, 24000, 44100,
48000.
Audio encoding format. One of
"pcm" (signed 16-bit LE), "mulaw", or
"alaw".Runtime-configurable settings for the STT service. See Settings
below.
P99 latency from speech end to final transcript in seconds. Override for your
deployment. See
stt-benchmark.
Settings
Runtime-configurable settings passed via thesettings constructor argument using XAISTTService.Settings(...). These can be updated mid-conversation with STTUpdateSettingsFrame. See Service Settings for details.
Usage
Basic Setup
With Custom Settings
With Multichannel Audio
Notes
- Connection management: The WebSocket connection is persistent and automatically reconnects if it drops mid-session. Audio is streamed continuously and the server emits
transcript.partialevents withis_finalandspeech_finalflags to mark utterance boundaries. - Language support: xAI STT accepts two-letter language codes. When set, the server applies Inverse Text Normalization for improved accuracy.
- Audio encoding: Supports PCM (signed 16-bit LE), μ-law, and A-law encoding formats. PCM is recommended for best quality.
- Settings updates: Changing settings requires reconnecting to the WebSocket. The service automatically handles disconnect and reconnect when settings are updated via
STTUpdateSettingsFrame.