chenhg5/cc-connect · error

weixin: empty audio

Error message

weixin: empty audio

What it means

Validation guard in Weixin SendAudio: the audio byte slice has zero length after reply-context resolution, so there is no voice data to convert to AMR and send.

Source

Thrown at platform/weixin/media_outbound.go:254

	ext := strings.TrimPrefix(strings.ToLower(filepath.Ext(file.FileName)), ".")
	switch ext {
	case "avi", "m4v", "mkv", "mov", "mp4", "mpeg", "mpg", "webm":
		return true
	default:
		return false
	}
}

// SendAudio implements core.AudioSender.
// Weixin voice messages require AMR or SILK format. Since SILK encoding is not
// widely supported, we convert to AMR format using ffmpeg.
func (p *Platform) SendAudio(ctx context.Context, replyCtx any, audio []byte, format string) error {
	rc, err := p.resolveReplyContext(replyCtx)
	if err != nil {
		return err
	}
	if len(audio) == 0 {
		return fmt.Errorf("weixin: empty audio")
	}

	// Convert to AMR format if not already AMR
	sendData := audio
	sendFormat := strings.ToLower(strings.TrimSpace(format))
	if sendFormat == "" {
		sendFormat = "wav" // TTS typically outputs WAV
	}
	if sendFormat != "amr" {
		converted, err := core.ConvertAudioToAMR(ctx, audio, sendFormat)
		if err != nil {
			return fmt.Errorf("weixin: convert %s to AMR: %w", sendFormat, err)
		}
		sendData = converted
		sendFormat = "amr"
	}

	slog.Debug("weixin: audio converted", "format", sendFormat, "size", len(sendData))

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Check len(audio) > 0 before calling SendAudio.
  2. Fix the TTS/recording step that produced empty audio and verify its output size.
  3. Pass a non-empty format or leave blank — the empty-audio error is purely about the byte payload, not the format.

Example fix

// before
wav, _ := tts.Synthesize(text) // error ignored
p.SendAudio(ctx, rc, wav, "wav") // weixin: empty audio
// after
wav, err := tts.Synthesize(text)
if err != nil || len(wav) == 0 { return fmt.Errorf("tts: %w", err) }
Defensive patterns

Strategy: validation

Validate before calling

if len(audio) == 0 { return errors.New("audio payload is empty; skipping send") }

Try / catch

if err := p.SendAudio(ctx, rc, audio, format); err != nil && strings.Contains(err.Error(), "empty audio") { log.Error("TTS/recording produced empty audio") }

Prevention

When it happens

Trigger: Calling SendAudio with audio == nil or audio == []byte{} (e.g. TTS/record step produced no output).

Common situations: Text-to-speech engine silently produced an empty buffer; microphone recording captured zero bytes; conversion pipeline failed upstream and returned empty data.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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