Repository navigation
fix(cli): refuse SRT and VTT files that are not UTF-8 instead of importing mojibake - #7559
Open
wonjangcloud9 wants to merge 1 commit into
Open
wonjangcloud9 wants to merge 1 commit into
wonjangcloud9 wants to merge 1 commit into
Conversation
…rting mojibake `transcribe` decoded every SRT and VTT as UTF-8 with replacement, so a subtitle file in a legacy East Asian encoding imported or exported "successfully" as U+FFFD characters. Most Korean subtitles from older tools are CP949 (EUC-KR): `transcribe subtitles.srt --to vtt` printed "Exported 3 words" and wrote `�ȳ��ϼ���` for 안녕하세요, and an import puts the same text into transcript.json and the captions. Subtitle files are now decoded strictly: UTF-16LE with its BOM as before, otherwise UTF-8 (a UTF-8 BOM is still dropped). Anything else stops with a message that names the likely encodings and the iconv command. Whisper JSON keeps the lenient decoder: whisper.cpp writes tokens that split a multi-byte character, which arrive as U+FFFD by design. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
transcribenow refuses an.srtor.vttfile that is not UTF-8 (or UTF-16LE with a BOM). Before, it imported or exported such a file as replacement characters. The error names the likely encodings and theiconvcommand that converts the file.Why
Subtitle files were decoded as UTF-8 with replacement, so a file in a legacy East Asian encoding "succeeded" as
U+FFFDtext. That is the common case for Korean subtitles from older tools, which save CP949 (EUC-KR). Shift_JIS and GBK files hit the same path. Three-cue Korean SRT, converted withiconv -f UTF-8 -t CP949:Before (main):
Importing it instead (
hyperframes transcribe cp949.srt) goes through the sameloadTranscriptand would put that text intotranscript.jsonand the patched caption HTML.After:
The same file as UTF-8, UTF-8 with a BOM, or UTF-16LE with a BOM exports
안녕하세요, 여러분.exactly as before.Related work
None found: I searched issues and PRs for encoding, CP949, EUC-KR, Shift_JIS, mojibake and "not UTF-8". #5843 and #6845 fixed nearby UTF-8 and BOM reads for project files and JSON flags.
How
loadTranscriptreads SRT and VTT through a newreadSubtitleText. It decodes UTF-16LE when the file starts with its BOM, asreadJsonFileTextdid, and otherwise usesTextDecoder("utf-8", { fatal: true }), which still drops a UTF-8 BOM. On invalid UTF-8 it throws, andreadTranscriptalready turns that into aninvalid_transcripterror.Whisper JSON keeps the lenient decoder on purpose. whisper.cpp writes token texts that split a multi-byte character, and those arrive as
U+FFFD(the transcript guide inskills/media-uselists the{ "text": "�" }tokens). A strict read there would reject real transcripts.I chose to refuse rather than guess an encoding. A CP949 byte sequence is often also valid in another legacy encoding, so a fallback could silently pick the wrong one.
Test plan
normalize.test.ts: a CP949.srtand.vtt(the bytes of 안녕하세요) now throw the encoding error. Both new cases fail on main, where they load asU+FFFDtext. A Korean SRT saved as UTF-8 with a BOM and as UTF-16LE with a BOM still loads, on main and here. 87/87 pass.transcribe <file> --to vtton the CP949, UTF-8, UTF-8+BOM and UTF-16LE files, plus the CP949 file aftericonv(outputs above).vitest --project unit src/whisper src/api: everything passes except 3sherpa.test.tsruntime-install cases, which fail the same way with main'snormalize.tson this machine. oxlint, oxfmt,tsc --noEmit, comment ratchet andfallow audit --base origin/mainare clean.docs/packages/cli.mdx(transcribe section).🤖 Generated with Claude Code