chenhg5/cc-connect · error

minimax tts: decode audio hex: %w

Error message

minimax tts: decode audio hex: %w

What it means

MiniMax encodes each TTS audio chunk in the SSE stream as a hex string in data.audio; this error is returned when hex.DecodeString fails on that chunk. A decode failure means the stream payload was not valid hex — typically a truncated/corrupted stream, a proxy mangling the body, or a non-hex error payload reaching the audio branch.

Source

Thrown at core/tts.go:396

			} `json:"base_resp"`
		}
		if err := json.Unmarshal([]byte(data), &chunk); err != nil {
			continue
		}
		if chunk.BaseResp.StatusCode != 0 {
			return nil, "", fmt.Errorf("minimax tts API error %d: %s", chunk.BaseResp.StatusCode, chunk.BaseResp.StatusMsg)
		}
		// MiniMax T2A v2 stream protocol: status=1 carries incremental audio
		// chunks; the final status=2 chunk re-sends the full audio as a
		// trailer for non-stream clients. Appending the trailer doubles the
		// audio length and makes the spoken text play twice, so skip it.
		if chunk.Data.Status == 2 {
			break
		}
		if chunk.Data.Audio != "" {
			audioBytes, err := hex.DecodeString(chunk.Data.Audio)
			if err != nil {
				return nil, "", fmt.Errorf("minimax tts: decode audio hex: %w", err)
			}
			audioBuf.Write(audioBytes)
		}
	}
	if err := scanner.Err(); err != nil {
		return nil, "", fmt.Errorf("minimax tts: read SSE stream: %w", err)
	}
	if audioBuf.Len() == 0 {
		return nil, "", fmt.Errorf("minimax tts: no audio data received")
	}
	return audioBuf.Bytes(), "mp3", nil
}

// ──────────────────────────────────────────────────────────────
// MimoTTS — Xiaomi MiMo-V2.5-TTS implementation
// ──────────────────────────────────────────────────────────────

// MimoTTS implements TextToSpeech using the Xiaomi MiMo-V2.5-TTS API,

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Check for an intercepting proxy/captive portal rewriting HTTPS bodies; bypass it or fix the proxy.
  2. Retry the synthesis — a single corrupted chunk is usually transient.
  3. Verify the configured base_url/API version still speaks the T2A v2 hex-chunk protocol after MiniMax updates.
  4. Report/inspect the raw chunk if reproducible: dump the SSE body to confirm which characters broke hex decoding.
Defensive patterns

Strategy: retry

Type guard

func isHex(s string) bool { _, err := hex.DecodeString(s); return err == nil }

Try / catch

if err != nil && strings.Contains(err.Error(), "decode audio hex") {
    // corrupted chunk: retry once; if persistent, log raw stream for provider support
}

Prevention

When it happens

Trigger: A data chunk's audio field contains non-hex characters (odd length, whitespace, HTML injected by an intermediary proxy); corrupted/partial SSE data from an unstable connection.

Common situations: Corporate proxy or captive portal rewriting response bodies; connection truncation mid-stream combined with parser quirks; MiniMax changing the wire format in a new API version.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/3ed1f17bd1dd20bd. Report an issue: GitHub.