]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
examples : Remove leading space from txt output (#3921)
authorCappuccino <redacted>
Sat, 11 Jul 2026 15:53:59 +0000 (23:53 +0800)
committerGitHub <redacted>
Sat, 11 Jul 2026 15:53:59 +0000 (17:53 +0200)
* 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
examples/cli/cli.cpp

index e505bf0e18de29b0499782eed16d6ba330e30b77..c64976a56375331c2446b3ba946757b3f6fabec8 100644 (file)
@@ -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";
     }
 }