Set the VAD threshold for speech-to-text
Set the VAD threshold for speech-to-text
vad_threshold (0.0–1.0) gates which audio segments count as speech. Segments below the threshold are skipped for transcription. 0 disables the gate. Lower values pick up quieter or noisier speech (narrowband telephony) and can produce spurious text for background noise.
Defaults differ by surface: batch REST defaults to 0.5; streaming WebSocket defaults to 0.08.
Batch REST
POST https://api.x.ai/v1/stt. Put option fields before file in the multipart body. Fields after file may be ignored.
Official skeleton, with vad_threshold added before file:
curl -X POST https://api.x.ai/v1/stt \
-H "Authorization: Bearer $XAI_API_KEY" \
-F format=true \
-F language=en \
-F "keyterm=Understand The Universe" \
-F vad_threshold=0.5 \
-F file=@audio.mp3
Same order in requests: options in data=, file in files=.
import os
import requests
response = requests.post(
"https://api.x.ai/v1/stt",
headers={"Authorization": f"Bearer {os.environ['XAI_API_KEY']}"},
files={"file": ("audio.mp3", open("audio.mp3", "rb"), "audio/mpeg")},
data=[
("format", "true"),
("language", "en"),
("keyterm", "Understand The Universe"),
("vad_threshold", "0.5"),
],
)
Streaming WebSocket
Add &vad_threshold=0.08 (or another value in 0.0–1.0) to the documented URL pattern:
wss://api.x.ai/v1/stt?sample_rate=16000&encoding=pcm&interim_results=true&language=en&keyterm=Understand+The+Universe
On streaming, the VAD gate does not change endpointing or speech_final timing. Other knobs on the same page include smart_turn / smart_turn_timeout and endpointing.
Pitfalls
- Batch default is
0.5. Streaming default is0.08. Do not mix them. 0disables the gate on both surfaces.- Batch: option fields must precede
file, or later fields may be ignored. - Console API credits are separate from SuperGrok's weekly pool on grok.com.