fix(deepgram): STT keyterm prompting is broken for non-Latin languages (Thai, Chinese, etc.)#1318
Open
tomasz-stefaniak wants to merge 1 commit intolivekit:mainfrom
Open
Conversation
`URL.searchParams.append()` already percent-encodes values on
serialization. The extra `encodeURIComponent()` call causes
double-encoding for non-ASCII characters (Thai, Chinese, etc.):
encodeURIComponent("ครับ") → "%E0%B8%84..."
searchParams.append re-encodes % → "%25E0%25B8%2584..."
This means:
1. Non-Latin keyterms arrive at Deepgram as percent-encoded strings
instead of actual text, making keyterm prompting ineffective.
2. The inflated URL length hits Deepgram's limits sooner — in our
testing, 13 Thai keyterms triggered a 400 rejection.
Latin-only keyterms are unaffected because encodeURIComponent is
a no-op for ASCII letters/digits, so this has been invisible to
English users.
The fix: let searchParams.append handle encoding on its own.
|
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.
Problem
SpeechStream.run()inplugins/deepgram/src/stt.ts(lines 201 & 203) callsencodeURIComponent()on each query parameter value before passing it toURL.searchParams.append(). SincesearchParams.append()already percent-encodes values on serialization, non-ASCII characters get double-encoded:This causes two issues:
Keyterm prompting is silently broken for non-Latin languages. Deepgram receives percent-encoded ASCII strings (
%E0%B8%84%E0%B8%A3%E0%B8%B1%E0%B8%9A) instead of the actual text (ครับ), so keyterms have no effect on transcription accuracy.400 rejections with modest keyterm counts. The double-encoded URL is ~45% larger. In our testing, just 13 Thai keyterms triggered a Deepgram 400 — while 12 succeeded. The same keyterms work fine in Latin scripts.
Latin-only keyterms are unaffected because
encodeURIComponentis a no-op for ASCII letters and digits — which is why this hasn't been caught until now.Fix
Remove the redundant
encodeURIComponent()calls and letsearchParams.append()handle encoding on its own.Reproduction script
Save and run with
npx tsx repro.ts(no dependencies needed):Script output