stream: avoid duplicate lines in file output#3866
Conversation
Add -fnd/--file-no-dup option (enabled by default) to only write finalized segments to file at n_new_line boundaries, avoiding the duplicate lines that occur when writing on every iteration. Fixes ggml-org#1056 Signed-off-by: Liu Zhangjian <liuzhangjian@uniontech.com>
|
Strong +1 — I hit exactly this building a Wayland dictation tool on top of The proposed 1. Key the "finalized" write off committed segments, not lines. In sliding mode ( 2. Cover VAD mode ( Backwards-compat via Happy to test a patch against the dictation/parse use-case (sliding and VAD, CPU and Vulkan) — I have repros for both duplication paths. |
Problem
The
streamexample writes to the output file (-fflag) on every iteration, producing duplicate/incomplete lines. This happens because stdout uses\r(carriage return) to overwrite the same line in-place, but the file output writes a new line every iteration. The result is a file filled with many intermediate transcriptions that are difficult to parse.Reported in #1056 with multiple users requesting a fix.
Observed
Running
./stream -f output.txtproduces a file like:Instead of the expected clean output:
Fix
-fnd/--file-no-dupflag (enabled by default) to only write finalized segments to file atn_new_lineboundariesn_segments_writtento avoid re-writing segments from previous cycles-fd/--file-dupflag to restore the old behavior for users who rely on it (e.g., real-time file monitoring in Vim)The fix is 1 file, ~35 lines changed (mostly the new write-at-boundary logic).
Fixes #1056