From: Cappuccino Date: Sat, 11 Jul 2026 15:53:59 +0000 (+0800) Subject: examples : Remove leading space from txt output (#3921) X-Git-Tag: upstream/1.9.2~37 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=080bbbe85230f624f0b52127f1ae1218247989f9;p=pkg%2Fggml%2Fsources%2Fwhisper.cpp examples : Remove leading space from txt output (#3921) * Fix #587: Remove leading space from txt output The BPE tokenizer used by Whisper produces tokens with leading spaces, causing each line in the txt output to start with an unwanted space. This fix strips leading whitespace (spaces and tabs) from each segment when writing to txt output files, improving the readability of the transcription output. Fixes: https://github.com/ggml-org/whisper.cpp/issues/587 --- diff --git a/examples/cli/cli.cpp b/examples/cli/cli.cpp index e505bf0e..c64976a5 100644 --- a/examples/cli/cli.cpp +++ b/examples/cli/cli.cpp @@ -465,7 +465,15 @@ static void output_txt(struct whisper_context * ctx, std::ofstream & fout, const speaker = estimate_diarization_speaker(pcmf32s, t0, t1); } - fout << speaker << text << "\n"; + if (!speaker.empty()) { + fout << speaker << text; + } else { + while (*text == ' ' || *text == '\t') { + text++; + } + fout << text; + } + fout << "\n"; } }