Skip to content

fix(speech): decode SSE stream to raw audio and handle EPIPE#60

Merged
RyanLee-Dev merged 1 commit intoMiniMax-AI:mainfrom
BLUE-coconut:fix/speech-stream-sse-decoding
Apr 9, 2026
Merged

fix(speech): decode SSE stream to raw audio and handle EPIPE#60
RyanLee-Dev merged 1 commit intoMiniMax-AI:mainfrom
BLUE-coconut:fix/speech-stream-sse-decoding

Conversation

@BLUE-coconut
Copy link
Copy Markdown
Contributor

Summary

Two fixes for mmx speech synthesize --stream:

1. SSE stream now outputs decoded binary audio

--stream was writing raw SSE/JSON/hex text to stdout. It now:

  • Parses SSE events via parseSSE()
  • Extracts .data.audio (hex string) from each event's JSON
  • Hex-decodes to raw binary MP3 and writes to stdout

This makes the documented example actually work:

mmx speech synthesize --text "Hello" --stream | mpv --no-terminal -

2. EPIPE no longer crashes the process

Added stdout.on('error') handler in main.ts. When a downstream process (e.g. mpv, head) exits early and closes the pipe, EPIPE is now treated as normal pipe-close with exit code 0, instead of an unhandled exception that crashes the CLI.

Before: Error: write EPIPE — unhandled, process exits with non-zero code
After: exit code 0

Fixes #54

Test plan

  • mmx speech synthesize --text "Test" --stream | head -c 4 — first bytes should be ID3 (valid MP3)
  • mmx speech synthesize --text "Test" --stream | head -c 1; echo $? — should print 0
  • mmx speech synthesize --text "Test" --out /tmp/out.mp3 — non-stream path unchanged

🤖 Generated with Claude Code

- Stream mode now parses SSE events, hex-decodes .data.audio, and
  writes raw binary MP3 to stdout (fixes --stream example piping to mpv)
- Add EPIPE handler to main.ts so piping to a downstream process that
  exits early (e.g. mpv, head) no longer crashes with unhandled error

Fixes MiniMax-AI#54

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@RyanLee-Dev RyanLee-Dev merged commit e6de2aa into MiniMax-AI:main Apr 9, 2026
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.

speech synthesize --stream outputs raw SSE/JSON instead of decoded audio bytes

2 participants