chenhg5/cc-connect · error
dingtalk: convert MP3 to AMR failed: %w
Error message
dingtalk: convert MP3 to AMR failed: %w
What it means
When the incoming audio is MP3, SendAudio first tries converting it to OGG (DingTalk voice requirement); if that fails it falls back to AMR conversion, and if that also fails this error wraps the AMR failure. DingTalk voice messages only support ogg/amr, so without a successful conversion the audio cannot be sent.
Source
Thrown at platform/dingtalk/dingtalk.go:1194
// DingTalk voice messages only support ogg/amr formats (not mp3).
func (p *Platform) SendAudio(ctx context.Context, rctx any, audio []byte, format string) error {
rc, ok := rctx.(replyContext)
if !ok {
return fmt.Errorf("dingtalk: SendAudio: invalid reply context type %T", rctx)
}
slog.Debug("dingtalk: SendAudio called", "format", format, "size", len(audio), "conversation_id", rc.conversationId)
// Convert MP3 to OGG if needed (DingTalk voice messages only support ogg/amr)
if strings.ToLower(format) == "mp3" {
slog.Debug("dingtalk: converting MP3 to OGG format (DingTalk requirement)")
oggAudio, err := core.ConvertMP3ToOGG(ctx, audio)
if err != nil {
slog.Warn("dingtalk: MP3 to OGG conversion failed", "error", err)
// Fallback: try AMR format instead
amrAudio, err := core.ConvertMP3ToAMR(ctx, audio)
if err != nil {
return fmt.Errorf("dingtalk: convert MP3 to AMR failed: %w", err)
}
audio = amrAudio
format = "amr"
} else {
audio = oggAudio
format = "ogg"
}
slog.Debug("dingtalk: audio converted", "new_format", format, "new_size", len(audio))
}
// Compress audio if too large (DingTalk limit is 2MB)
const maxAudioSize = 2 * 1024 * 1024
if len(audio) > maxAudioSize {
slog.Debug("dingtalk: audio too large, compressing", "size", len(audio), "max", maxAudioSize)
compressed, compressedFormat, err := p.compressAudio(ctx, audio, format)
if err != nil {
slog.Warn("dingtalk: compression failed, using original", "error", err)
} else {View on GitHub (pinned to 4000b2338a)
Solutions
- Verify the conversion tool (ffmpeg) is installed and on PATH: ffmpeg -version
- Validate the input audio is a non-empty, well-formed MP3
- Pre-convert audio to OGG or AMR before calling SendAudio to skip conversion
- Check the wrapped error for the converter's specific complaint
Example fix
// before
amrAudio, err := core.ConvertMP3ToAMR(ctx, audio)
if err != nil { return fmt.Errorf("dingtalk: convert MP3 to AMR failed: %w", err) }
// after (pre-validate)
if len(audio) == 0 { return errors.New("dingtalk: empty audio payload") }
if _, err := exec.LookPath("ffmpeg"); err != nil { return fmt.Errorf("dingtalk: ffmpeg required for audio conversion: %w", err) } Defensive patterns
Strategy: fallback
Validate before calling
if len(audio) == 0 { return errors.New("empty audio") }
if _, err := exec.LookPath("ffmpeg"); err != nil { return errors.New("ffmpeg not installed; cannot convert MP3 for DingTalk") } Try / catch
if err := p.SendAudio(ctx, rc, mp3Data, "mp3"); err != nil && strings.Contains(err.Error(), "convert MP3") {
// supply pre-converted OGG instead
err = p.SendAudio(ctx, rc, oggData, "ogg")
} Prevention
- Install ffmpeg on hosts running cc-connect and verify it at startup (doctor check)
- Prefer sending OGG/AMR audio natively to skip conversion entirely
- Validate audio payloads are non-empty and well-formed before sending
- Check audio sample rates are within ffmpeg-supported ranges
When it happens
Trigger: Sending an MP3 audio message where core.ConvertMP3ToOGG fails (e.g. ffmpeg not installed) and the fallback core.ConvertMP3ToAMR also fails (ffmpeg missing, malformed/corrupt MP3 input, or unsupported sample rate/bitrate).
Common situations: ffmpeg (or the converter binary) not installed on the host, corrupted or zero-byte audio from the agent, unusual MP3 encodings the converter can't handle.
Understand the failure class
Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.
Related errors
- ffmpeg not found: %w
- ffmpeg compression failed: %w (stderr: %s)
- %s: convert to opus: %w
- ffmpeg not found in PATH: install ffmpeg to enable voice mes
- ffmpeg conversion failed: %w (stderr: %s)
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/21bcc1fd8705c286.
Report an issue: GitHub.