fix(speech): serialize pronunciation dictionary correctly#188
Open
kartikkabadi wants to merge 1 commit into
Open
fix(speech): serialize pronunciation dictionary correctly#188kartikkabadi wants to merge 1 commit into
kartikkabadi wants to merge 1 commit into
Conversation
06e0498 to
2e5cc47
Compare
Co-authored-by: Cursor <cursoragent@cursor.com>
2e5cc47 to
76e7869
Compare
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.
Summary
mmx speech synthesize --pronunciationbuilt the wrong JSON shape forpronunciation_dict, so every request using the flag was rejected by the MiniMax T2A API (/v1/t2a_v2). Custom pronunciation — e.g. Chinese polyphonic characters (多音字) — was completely unusable from the CLI.Fixes #187.
Before
The CLI split each
word/(pronunciation)value on/and rebuilt it as{ tone, text }inside an array.After
Each value is preserved verbatim inside a
tonestring array on an object, matching the officialPronunciationDictschema. Dry-run output matches the API-requiredpronunciation_dictshape. The payload shape is confirmed by the official API documentation and the reporter's raw API reproduction in #187.Root cause
Two places encoded the wrong shape:
src/types/api.ts—SpeechRequest.pronunciation_dictwas typed asArray<{ tone: string; text: string }>, describing an array of objects.src/commands/speech/synthesize.ts— the--pronunciationblock split each value on/and rebuilt it as{ tone: to, text: from }, then wrapped the results in an array.The API rejects the array form with
Mismatch type open_platform.PronunciationDict with value array.Changes
src/types/api.ts—pronunciation_dict?: { tone: string[] }to match the API contract.src/commands/speech/synthesize.ts— pass each--pronunciationvalue through verbatim intobody.pronunciation_dict = { tone: flags.pronunciation as string[] }instead of splitting it. No CLI-side validation of pronunciation syntax — the MiniMax API is the source of truth for pronunciation syntax.test/commands/speech/synthesize.test.ts— 2 dry-run regression tests (see below).The change is narrowly scoped to issue #187 — no unrelated refactors.
SDK consumers
SpeechRequestis an exported type used by the publicSpeechSDK. Any external code building the oldArray<{ tone; text }>shape will get a compile-time type error after this change. That code was already broken at runtime (the API never accepted the array form), so this surfaces the break earlier — at compile time instead of at the API call. The SDK itself forwardsSpeechRequestcorrectly viatoMergedand requires no runtime changes. To migrate, pass{ tone: ["word/(pronunciation)"] }.Tests
Added 2 focused dry-run regression tests in
test/commands/speech/synthesize.test.ts:--pronunciation serializes multiple values with the API-compatible shape— repeated--pronunciationvalues covering both the pinyin form (处理/(chu3)(li3)) and the plain-replacement form (危险/dangerous) shown in the official API docs. Assertspronunciation_dictis an object with atonestring array (not the old array-of-objects shape) and that each value is preserved verbatim — no splitting, trimming, or rewriting.--pronunciation with a single value serializes under tone— single value (Omg/Oh my god, from the official API docs example).Verification
bun test test/commands/speech/synthesize.test.ts— 20/20 pass (2 new)bun run typecheck— passbun run lint— no new errors (2 pre-existing errors in unrelated test files onupstream/main)bun test— no new failures (40 pre-existing failures onupstream/mainare unrelated to speech synthesis; +2 tests, +2 pass)bun run build— passReproduction
Before:
Error: API error: invalid params, Mismatch type open_platform.PronunciationDict with value arrayAfter: dry-run output matches the API-required
pronunciation_dictshape.