transcribe.cpp icon indicating copy to clipboard operation
transcribe.cpp copied to clipboard

--batch-jsonl emits invalid JSON: backslashes in the file field are not escaped (every line on Windows)

Open raykuo998 opened this issue 4 months ago • 2 comments

--batch-jsonl writes the file field into the output line without JSON string escaping, so every line whose path contains a backslash is invalid JSON — i.e. every line on Windows. The text field is escaped correctly; only file bypasses it.

Observed at commit 5a5a496.

Repro

transcribe-cli.exe --batch list.txt -m moss-Q4_K_M.gguf --backend cpu --batch-jsonl --timestamps none -q > out.jsonl

where list.txt holds absolute Windows paths, one per line:

C:\Users\rayku\AppData\Local\Temp\claude\C--Users-rayku\9b32cefe-...\scratchpad\rg\h1.wav

Then parse it with any strict JSON parser:

node -e "require('fs').readFileSync('out.jsonl','utf8').trim().split('\n').map(JSON.parse)"

Expected

Every output line is valid JSON, with backslashes escaped:

{"file":"C:\\Users\\rayku\\...\\h1.wav","text":"...","mel_ms":11.0,"encode_ms":9109.9,"decode_ms":1879.4}

Actual

Backslashes are emitted raw, producing invalid string escapes (\U, \r, \9, … depending on the path):

{"file":"C:\Users\rayku\AppData\Local\Temp\claude\C--Users-rayku\9b32cefe-...\scratchpad\rg\h1.wav","text":"[0.65][S01]前程部烧进AI的不是SpaceX吗?[3.56]","mel_ms":11.0,"encode_ms":9109.9,"decode_ms":1879.4}
SyntaxError: Bad escaped character in JSON at position 12

JSON.parse / json.loads throw on every such line, which defeats the purpose of --batch-jsonl.

Environment

Windows 11 ARM64. Path handling here is OS-level, not arch-specific — any Windows build should reproduce it. A POSIX path containing a " or a backslash would hit the same code path.

Fix

Run the file value through the same JSON string escaper already used for text before writing it.

Workaround used downstream

Ignore the file field, rely on input list order, and regex text out of the raw line.

raykuo998 avatar Jul 29 '26 09:07 raykuo998

addressed in https://github.com/handy-computer/transcribe.cpp/commit/553f1099a2b3a5bc4421894be171f09960fc0f3a

cjpais avatar Aug 03 '26 08:08 cjpais

I retested this on 553f109 - paths with embedded double-quotes now come through the batch JSONL cleanly (every line parses with json.loads, including the error rows for files that fail to load). Thanks for the quick fix!

victorhooi avatar Aug 06 '26 03:08 victorhooi