Stream Python speech to text output live instead of after the process exits#12247
Merged
niksedk merged 1 commit intoJul 7, 2026
Merged
Conversation
The CTranslate2 engine got --verbose True so its segment lines stream to the console, but they still never appeared during the run: without a terminal attached Python block-buffers stdout (about 8 KB), so every line sat in the buffer until the process exited. A 45 minute file decodes for many minutes with a completely empty console, which reads as frozen. Verified against the shipped whisper-ctranslate2 bundle with output piped the same way Subtitle Edit reads it: without PYTHONUNBUFFERED the first line arrives only when the process ends; with it, lines arrive the moment they are printed. Set PYTHONUNBUFFERED=1 wherever PYTHONIOENCODING is already set (the generic engine path and the MLX helper path), so all Python-based engines stream their progress live.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Python based speech to text engines (Whisper CTranslate2, MLX Whisper) showed a completely empty console while transcribing; all output appeared at once when the process finished. A 45 minute file decodes for many minutes with a blank console, which reads as frozen, and several users assumed the engine was looping without transcribing.
Cause and fix
Without a terminal attached, Python block buffers stdout (about 8 KB), so newline terminated progress lines sit in the buffer until the process exits. Running the same command in a terminal is line buffered, which is why the problem never reproduces there.
Verified against the shipped whisper-ctranslate2 bundle with output piped the same way Subtitle Edit reads it: without
PYTHONUNBUFFEREDthe first line arrives only when the process ends; with it, lines arrive the moment they are printed.The fix sets
PYTHONUNBUFFERED=1whereverPYTHONIOENCODINGis already set (the generic engine path and the MLX helper path), so all Python based engines stream their progress live.