Skip to content

fix(speech): correctly enable and download subtitles for TTS#105

Merged
RyanLee-Dev merged 2 commits intoMiniMax-AI:mainfrom
raylanlin:fix/speech-subtitles
Apr 17, 2026
Merged

fix(speech): correctly enable and download subtitles for TTS#105
RyanLee-Dev merged 2 commits intoMiniMax-AI:mainfrom
raylanlin:fix/speech-subtitles

Conversation

@raylanlin
Copy link
Copy Markdown
Collaborator

Summary

Fixes `--subtitles` flag for `mmx speech synthesize`, which was not working due to two API spec mismatches.

Root Causes

  1. Wrong request parameter: Code sent `subtitle: true` but the API expects `subtitle_enable: true`
  2. Wrong response field: Code expected inline `subtitle_info` object, but API returns `subtitle_file` — a download URL to a JSON file

Changes

File Change
`src/types/api.ts` `subtitle` → `subtitle_enable`; `subtitle_info` → `subtitle_file`; remove dead `SubtitleInfo` type
`src/commands/speech/synthesize.ts` Fix request param; download subtitle JSON from URL; convert to SRT format; add error handling + quiet mode support
`test/commands/speech/synthesize.test.ts` Add dry-run test verifying `subtitle_enable: true` in request body
`skill/SKILL.md` Update `--subtitles` docs with usage example

How It Works

When `--subtitles` is passed:

  1. Request sets `subtitle_enable: true`
  2. API returns `data.subtitle_file` — an OSS URL to a JSON subtitle file
  3. CLI downloads the JSON, converts timestamps to SRT format, and saves alongside the audio file
  4. Example: `--out hello.mp3` → saves `hello.mp3` + `hello.srt`

SRT Output Example

```
1
00:00:00,000 --> 00:00:05,438
你好,这是第一条字幕。接着是第二句。

2
00:00:05,580 --> 00:00:06,764
谢谢收听。
```

Testing

  • Built locally with `bun run build`
  • Tested against live API with multiple Chinese and English texts
  • Subtitle file correctly generated with proper SRT timestamps
  • Dry-run test verifies correct request parameter name
  • All existing tests pass

Closes #102

- Fix request parameter: `subtitle` → `subtitle_enable` per official API spec
- Fix response parsing: API returns `data.subtitle_file` (URL), not inline `subtitle_info`
- Download subtitle JSON from URL and convert to SRT format alongside audio file
- Remove dead `SubtitleInfo` type from api.ts
- Add dry-run test for `--subtitles` flag
- Update skill documentation with subtitle usage examples

Fixes MiniMax-AI#102
Newer Bun versions add 'preconnect' to typeof fetch, breaking direct
assignment to globalThis.fetch. Cast through any to satisfy TypeScript.

This is a pre-existing CI failure, not related to the subtitle fix.
@RyanLee-Dev RyanLee-Dev merged commit b8292ae into MiniMax-AI:main Apr 17, 2026
1 check failed
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.

语音合成 --subtitles 命令不生效

2 participants