Live, local-first subtitles for X Spaces and X broadcasts, with English ↔ Spanish translation and optional paid translation backends.
English · Español
[20:36:30] They don't have free and fair elections.
[20:36:30] → No tienen elecciones libres y justas.
- Free and open source: MIT license.
- Free default stack:
faster-whisper tiny+ offline OPUS-MT EN→ES. - No API key required. Works offline after the models are downloaded.
- Optional real-time profile for CPU-only machines.
- Optional OpenAI-compatible translator for users who prefer a paid model.
- Terminal output plus
/tmp/xspace_subtitles.txtor a FIFO for OBS/status bars.
- What it does
- Architecture
- Requirements
- Omarchy / Arch Linux quick install
- Installation
- Quick start
- Real-time mode
- CLI reference
- Output and subtitle file
- Free vs. paid models
- Model recommendations
- Alternative ASR backends
- Environment variables
- Troubleshooting
- Development
- Privacy and legal notes
- License
xspace-translate takes a public X Space or X broadcast URL and:
- Resolves the live HLS stream with
yt-dlp. - Decodes it with
ffmpegto raw 16 kHz / 16-bit / mono PCM. - Segments speech with WebRTC VAD.
- Runs the optimal Whisper path for the requested direction:
- EN→ES: English speech → English text → local EN→ES translation.
- ES→EN: Spanish speech → English directly with Whisper's translation task (no extra text model).
- same language: transcription only.
- Optionally uses an OpenAI-compatible API when translating into Spanish from an English or auto-detected source.
- Prints timestamped subtitles and optionally writes the latest target line to a file or FIFO.
The default path is free, local and private: audio never leaves the machine.
| Spoken language | Target | Path |
|---|---|---|
en |
es |
Whisper English transcription + OPUS-MT EN→ES |
es |
en |
Direct Whisper speech translation to English |
auto |
es |
Whisper translation to English + OPUS-MT EN→ES |
auto |
en |
Direct Whisper speech translation to English |
es |
es |
Spanish transcription only |
en |
en |
English transcription only |
Use --source-lang when you know the spoken language: it improves ASR
accuracy, selects the best path, and avoids unnecessary model work.
X Space / broadcast URL
│
▼
yt-dlp ──► HLS (.m3u8)
│
▼
ffmpeg ──► 16 kHz, 16-bit, mono PCM
│
▼
VAD segmenter ──► queue.Queue
│ │
│ ▼
│ inference worker
│ Whisper (transcribe/translate)
│ OPTIONAL EN→ES translator
│ │
▼ ▼
capture thread Rich terminal + file/FIFO
Audio capture and inference run in separate threads. The queue is unbounded so a slow model never blocks stream capture.
- Python 3.10+
ffmpegyt-dlp- Linux or macOS (tested on Linux). Windows is not officially tested because the stream reader uses POSIX pipe selectors.
- Internet access for the first model downloads.
Install the system tools:
# Arch Linux / Omarchy
sudo pacman -S --needed ffmpeg yt-dlp python python-pip
# Debian / Ubuntu
sudo apt update
sudo apt install ffmpeg yt-dlp python3 python3-venv python3-pip
# macOS
brew install ffmpeg yt-dlp pythonOn Omarchy (or Arch Linux) you can install a ready-to-run CLI and a desktop launcher with one command:
git clone https://github.com/gaboxarg/xspace-translate.git
cd xspace-translate
./scripts/install-omarchy.shThe installer:
- checks and installs missing system packages with
pacman(ffmpeg,yt-dlp,python,gum,xdg-terminal-exec); - creates
.venvand installs the package in editable mode; - installs
xspace-translateand the friendlyxspace-translate-easylauncher in~/.local/bin; - adds an X Space Translate entry to the application menu with an icon.
After installation, launch it from the application menu or run:
xspace-translate-easyThe launcher asks for:
- the X Space / broadcast URL;
- the direction: EN→ES, ES→EN, auto→Spanish, auto→English;
- a profile: real-time CPU, higher accuracy, maximum GPU quality, or custom;
- an optional subtitle file.
For advanced options (paid translator, FIFO, custom parameters), use:
xspace-translate --helpInstaller options:
./scripts/install-omarchy.sh --no-deps # skip pacman
./scripts/install-omarchy.sh --no-desktop # CLI only, no menu entry
./scripts/install-omarchy.sh --yes # accept dependency installRemove the desktop integration (the repository, .venv and downloaded models
are kept):
./scripts/uninstall-omarchy.shgit clone https://github.com/gaboxarg/xspace-translate.git
cd xspace-translate
python -m venv .venv
source .venv/bin/activate
pip install -e .For development tools:
pip install -e ".[dev]"The first run downloads Whisper tiny (~75 MB) for all directions. The
EN→ES text model (~88 MB) is downloaded only when translating into
Spanish from an English or auto-detected source:
| Component | Approximate size | Used by | Cache |
|---|---|---|---|
Whisper tiny |
~75 MB | All directions | ~/.cache/huggingface/hub |
| OPUS-MT EN→ES | ~88 MB | EN→ES and auto→ES | ~/.cache/xspace-translate/models/en_es |
After the Whisper download, ES→EN works offline without any extra text model.
xspace-translate \
"https://x.com/i/spaces/YOUR_SPACE_ID" \
--realtime \
--subtitle-file /tmp/xspace_subtitles.txtor without installing the console script:
python -m xspace_translate \
"https://x.com/i/spaces/YOUR_SPACE_ID" \
--realtime \
--subtitle-file /tmp/xspace_subtitles.txtStop with Ctrl+C. Pending VAD segments are flushed before exit.
Spanish → English:
xspace-translate \
"https://x.com/i/spaces/SPANISH_SPACE_ID" \
--source-lang es \
--lang en \
--realtimeEnglish → Spanish (default target):
xspace-translate \
"https://x.com/i/spaces/ENGLISH_SPACE_ID" \
--source-lang en \
--lang es \
--realtimeIf you do not know the source language, leave --source-lang auto (default).
--realtime is the low-latency profile:
- Whisper
tinyis selected automatically unless--modelis given. - End-of-speech silence: 250 ms.
- Maximum segment length: 3000 ms.
- HLS playback starts at the live edge instead of three segments behind it.
On a 4-core CPU, the default tiny model takes roughly 1.2–1.5 s per 3 s
chunk, plus ~0.2–0.4 s for local translation when translating into
Spanish. ES→EN uses direct Whisper translation and skips that extra stage.
Captions therefore arrive with about 1.5–2 s of latency, in updates
roughly every 3 s of continuous speech.
Tuning:
# More responsive, but more fragmented phrases
--realtime --max-segment-ms 2000
# More complete phrases, slightly more latency
--realtime --max-segment-ms 4000
# Change the pause threshold
--realtime --silence-ms 400Without --realtime, the standard profile uses 800 ms of silence and 4 s
maximum segments.
xspace-translate [OPTIONS] URL
| Option | Default | Description |
|---|---|---|
URL |
required | Public X Space or broadcast URL. |
--model |
tiny |
Whisper model: tiny, base, small, medium, large-v3, or a local model path. |
--device |
cpu |
cpu, cuda, or auto (passed to faster-whisper). |
--lang, --target-lang |
es |
Target language: es or en. |
--source-lang |
auto |
Spoken language: auto, en or es. Set es for Spanish→English. |
--translator |
local |
EN→ES backend used when translating into Spanish: local (free/offline) or openai (paid/hosted API). |
--translator-model |
gpt-4o-mini for openai |
Paid translator model name. |
--translator-api-base |
https://api.openai.com/v1 |
Base URL for the OpenAI-compatible endpoint. |
--realtime |
off | Low-latency profile: tiny model, 250 ms silence, 3 s segments. |
--silence-ms |
800 / 250 realtime |
Silence that closes an utterance, in milliseconds. |
--max-segment-ms |
4000 / 3000 realtime |
Maximum utterance duration before a forced cut. |
--compute-type |
int8 |
CTranslate2 compute type (int8, float16, float32, ...). |
--cpu-threads |
4 |
CPU threads used by CTranslate2. |
--subtitle-file |
disabled | Write the latest target-language line to this path. |
--fifo |
off | Create --subtitle-file as a FIFO and write non-blocking. |
-v, --verbose |
off | Enable debug logging. |
--version |
Show version and exit. | |
-h, --help |
Show help and exit. |
Examples:
# English → Spanish, free/local, real-time
xspace-translate "https://x.com/i/broadcasts/ABC" \
--source-lang en --lang es --realtime
# Spanish → English, free/local, real-time (direct Whisper translation)
xspace-translate "https://x.com/i/broadcasts/ABC" \
--source-lang es --lang en --realtime
# Higher-quality local model on a strong CPU/GPU
xspace-translate "https://x.com/i/broadcasts/ABC" \
--model small --device cuda --source-lang es --lang en
# Automatic source detection; target Spanish
xspace-translate "https://x.com/i/broadcasts/ABC" --realtime
# Paid/hosted EN→ES translation with an OpenAI-compatible API
export OPENAI_API_KEY="sk-..."
xspace-translate "https://x.com/i/broadcasts/ABC" --realtime --translator openaiBest-quality presets:
# GPU, maximum quality (either direction)
xspace-translate "URL" \
--source-lang es --lang en \
--model large-v3 --device cuda --compute-type float16
# CPU, English → Spanish
xspace-translate "URL" \
--source-lang en --lang es \
--model tiny --realtime
# CPU, Spanish → English
xspace-translate "URL" \
--source-lang es --lang en \
--model tiny --realtimeWhen translating into Spanish, the terminal shows the English intermediate in dim text and the Spanish translation in green. Direct Spanish→English translation shows the English result in green (there is no separate intermediate text):
[20:36:30] They don't have free and fair elections.
[20:36:30] → No tienen elecciones libres y justas.
[21:10:04] → They don't have free and fair elections.
Write only the latest target-language line to a regular file:
xspace-translate "URL" --realtime \
--subtitle-file /tmp/xspace_subtitles.txtRead it from another program:
tail -f /tmp/xspace_subtitles.txtUse a FIFO (non-blocking: lines are dropped when no reader is connected):
# Terminal 1
mkfifo /tmp/xspace_subs.fifo 2>/dev/null || true
cat /tmp/xspace_subs.fifo
# Terminal 2
xspace-translate "URL" --realtime \
--subtitle-file /tmp/xspace_subs.fifoAn existing FIFO is detected automatically. --fifo creates it when missing.
- ASR:
faster-whisper tiny(MIT). - EN→ES translation: OPUS-MT via Argos (open model, ~88 MB).
- ES→EN: direct Whisper speech translation; no text model is downloaded.
- VAD: WebRTC VAD.
- No account, API key or network connection is needed after the model downloads.
The paid backend is used only when the target is Spanish and the source
is English or auto. Use any service that implements
POST /chat/completions with the OpenAI schema. The app sends only the
English text, not the audio.
export OPENAI_API_KEY="sk-..."
xspace-translate "URL" --realtime \
--translator openai \
--translator-model gpt-4o-miniOpenRouter example:
export XSPACE_TRANSLATE_API_KEY="sk-or-..."
export XSPACE_TRANSLATE_API_BASE="https://openrouter.ai/api/v1"
export XSPACE_TRANSLATE_MODEL="openai/gpt-4o-mini"
xspace-translate "URL" --translator openaiLocal OpenAI-compatible server (for example Ollama or vLLM):
export XSPACE_TRANSLATE_API_BASE="http://localhost:11434/v1"
export XSPACE_TRANSLATE_MODEL="your-model"
xspace-translate "URL" --translator openaiNotes:
- API keys are read from environment variables only; there is no
--api-keyflag that could leak into shell history. - If the paid API fails, the engine logs a warning and falls back to the English text for that segment instead of stopping the stream.
- The paid translator sends English text to the configured provider. Check the provider's privacy and billing terms.
- Spanish→English does not use the paid translator because Whisper's translation task already produces English directly.
- The current paid integration covers text translation. Audio ASR remains local Whisper; a cloud ASR adapter would require a small additional backend.
Free Whisper models are selectable with --model:
xspace-translate "URL" --model base
xspace-translate "URL" --model small --device cudaFor a custom text translator, implement:
from xspace_translate.engine import TranslationEngine
class MyTranslator:
def translate(self, text: str) -> str:
return "..."
engine = TranslationEngine(translator=MyTranslator())TranslationEngine accepts any object implementing that translate method.
| Model | Size | Recommended use |
|---|---|---|
tiny |
~75 MB | Default. Best choice for real-time on 4-core CPUs. |
base |
~145 MB | Better accuracy; needs a stronger CPU or GPU for real time. |
small |
~480 MB | Good accuracy; GPU recommended. Measured at 10–15 s per 3 s chunk on a 4-core CPU. |
medium |
~1.5 GB | GPU recommended. |
large-v3 |
~3 GB | Best quality; GPU strongly recommended. |
| local path | — | Any faster-whisper-compatible model directory. |
Measured on a 4-core CPU with int8:
| Model | 24 s audio (full) | 3 s chunks |
|---|---|---|
tiny |
~4.5 s | ~1.3 s |
| Parakeet TDT 0.6B v3 ONNX int8 | ~20.8 s | ~3.0 s |
small |
— | ~10–15 s |
Timings vary by CPU, GPU, thermals and model cache.
For the best quality, prefer --model large-v3 --device cuda --compute-type float16. For real-time CPU use tiny and --realtime.
Spanish→English quality improves substantially with base/small/large
because Whisper performs speech translation directly in that direction.
NVIDIA Parakeet TDT 0.6B v3 is an excellent multilingual ASR model (25 European languages, punctuation/capitalization, ~6.34% average WER on the Open ASR Leaderboard). It is not included by default because:
- It is ASR only; it does not translate. The EN→ES stage is still needed.
- It is not natively streaming. Community streaming wrappers use overlapping windows and add ~2–4 s of lookahead latency.
- On the 4-core CPU used for this project it was slower than Whisper tiny in ONNX int8 form (~20.8 s for a 24 s clip vs ~4.5 s).
- It shines on GPUs and on machines with more CPU cores.
For true low-latency streaming on CPU, NVIDIA Nemotron ASR Streaming or a
sherpa-onnx streaming bundle is a better architectural fit than Parakeet v3.
Those backends are not wired into this app yet; contributions are welcome.
| Variable | Used by | Description |
|---|---|---|
OPENAI_API_KEY |
paid translator | Fallback API key. |
XSPACE_TRANSLATE_API_KEY |
paid translator | Preferred API key variable. |
XSPACE_TRANSLATE_API_BASE |
paid translator | OpenAI-compatible base URL. |
OPENAI_BASE_URL |
paid translator | Fallback base URL. |
XSPACE_TRANSLATE_MODEL |
paid translator | Model name. |
XDG_CACHE_HOME |
local translator | Changes the cache root; model is stored under <cache>/xspace-translate/models/en_es. |
HF_HOME |
Whisper | Changes the Hugging Face cache root. |
Test resolution directly:
python -c 'from xspace_translate.stream import get_hls_url; print(get_hls_url("YOUR_URL"))'If yt-dlp reports login/age/region errors:
yt-dlp -USome Spaces require browser cookies. The current get_hls_url helper does not
expose a cookie option; this can be added if needed.
X HLS URLs contain signed tokens that can expire. Restart the command to resolve a fresh URL. The streamer retries short network interruptions internally.
Install them with your system package manager and verify:
ffmpeg -version
yt-dlp --versionThis project depends on webrtcvad-wheels, which provides the webrtcvad
module without the old pkg_resources issue. Reinstall dependencies:
pip install -e . --force-reinstall- Use
--realtime(especially on CPU). - Keep
--model tiny. - Reduce
--max-segment-msto 2000 for faster updates, accepting more fragmented phrases. - If using
smallor larger on a 4-core CPU, latency will not be real-time. - A GPU (
--device cuda) is the biggest speed-up for larger models.
- Verify
OPENAI_API_KEY/XSPACE_TRANSLATE_API_KEY. - Check the base URL includes the API version, e.g.
https://api.openai.com/v1. - Check the model name supported by your provider.
- If the API is unreachable, the pipeline continues in English with a warning.
FIFO writes are non-blocking by design. If no reader is connected, the line is
dropped so inference is never blocked. Start cat/your reader before the CLI.
pip install -e ".[dev]"
pytest
ruff check xspace_translate tests
# Run without installing the console script
python -m xspace_translate --helpProject layout:
xspace_translate/
├── stream.py # yt-dlp + ffmpeg HLS capture, reconnects
├── vad.py # WebRTC VAD segmentation and float32 output
├── engine.py # Whisper + translation orchestration
├── translator.py # local OPUS-MT and OpenAI-compatible translators
├── output.py # Rich terminal output, file/FIFO subtitles
└── cli.py # click application and producer/consumer pipeline
scripts/
├── install-omarchy.sh # Omarchy/Arch installer
├── xspace-translate-easy # interactive launcher
└── uninstall-omarchy.sh # desktop integration removal
packaging/
├── xspace-translate.desktop # application menu entry
└── xspace-translate.svg # icon
tests/ # pytest suite (no network or model downloads)
- The default stack processes everything locally.
- The paid translator sends only English text to the configured API.
- Use the tool only with content you have the right to access and transcribe, and respect X's terms of service and applicable law.
- This project is not affiliated with X, NVIDIA, OpenAI, Argos Translate or the OPUS project.
MIT. See LICENSE.
Model and library licenses remain with their respective authors. Whisper and faster-whisper are MIT-licensed; the OPUS-MT/Argos model is distributed under open model terms; WebRTC VAD is BSD-licensed.