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
This commit is contained in:
Cappuccino
2026-07-11 23:53:59 +08:00
committed by GitHub
parent 7695a53312
commit 080bbbe852

View File

@@ -465,7 +465,15 @@ static void output_txt(struct whisper_context * ctx, std::ofstream & fout, const
speaker = estimate_diarization_speaker(pcmf32s, t0, t1); 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";
} }
} }