Skip to content

fix(speech): serialize pronunciation dictionary correctly#188

Open
kartikkabadi wants to merge 1 commit into
MiniMax-AI:mainfrom
kartikkabadi:fix/pronunciation-dict-shape
Open

fix(speech): serialize pronunciation dictionary correctly#188
kartikkabadi wants to merge 1 commit into
MiniMax-AI:mainfrom
kartikkabadi:fix/pronunciation-dict-shape

Conversation

@kartikkabadi

@kartikkabadi kartikkabadi commented Jul 10, 2026

Copy link
Copy Markdown

Summary

mmx speech synthesize --pronunciation built the wrong JSON shape for pronunciation_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

"pronunciation_dict": [
  { "tone": "(chong2)", "text": "" }
]

The CLI split each word/(pronunciation) value on / and rebuilt it as { tone, text } inside an array.

After

"pronunciation_dict": {
  "tone": ["处理/(chu3)(li3)", "危险/dangerous"]
}

Each value is preserved verbatim inside a tone string array on an object, matching the official PronunciationDict schema. Dry-run output matches the API-required pronunciation_dict shape. 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.tsSpeechRequest.pronunciation_dict was typed as Array<{ tone: string; text: string }>, describing an array of objects.
  • src/commands/speech/synthesize.ts — the --pronunciation block 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.tspronunciation_dict?: { tone: string[] } to match the API contract.
  • src/commands/speech/synthesize.ts — pass each --pronunciation value through verbatim into body.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

SpeechRequest is an exported type used by the public SpeechSDK. Any external code building the old Array<{ 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 forwards SpeechRequest correctly via toMerged and 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 --pronunciation values covering both the pinyin form (处理/(chu3)(li3)) and the plain-replacement form (危险/dangerous) shown in the official API docs. Asserts pronunciation_dict is an object with a tone string 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 — pass
  • bun run lint — no new errors (2 pre-existing errors in unrelated test files on upstream/main)
  • bun test — no new failures (40 pre-existing failures on upstream/main are unrelated to speech synthesis; +2 tests, +2 pass)
  • bun run build — pass

Reproduction

mmx speech synthesize \
  --text "我要去重庆出差。" \
  --pronunciation "重/(chong2)" \
  --out out.mp3

Before: Error: API error: invalid params, Mismatch type open_platform.PronunciationDict with value array
After: dry-run output matches the API-required pronunciation_dict shape.

Co-authored-by: Cursor <cursoragent@cursor.com>
@kartikkabadi kartikkabadi force-pushed the fix/pronunciation-dict-shape branch from 2e5cc47 to 76e7869 Compare July 10, 2026 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] speech synthesize --pronunciation sends wrong pronunciation_dict shape (array instead of {"tone":[...]}), API rejects it

1 participant