chenhg5/cc-connect · error
telegram: SendAudio: convert %s to opus: %w
Error message
telegram: SendAudio: convert %s to opus: %w
What it means
SendAudio wraps failures from telegramConvertAudioToOpus with "telegram: SendAudio: convert %s to opus: ". This path runs only for formats other than ogg/opus/mp3/m4a (e.g. wav, flac): the audio must be transcoded to Opus/OGG for Telegram voice messages and the ffmpeg conversion failed.
Source
Thrown at platform/telegram/telegram.go:1203
func (p *Platform) SendAudio(ctx context.Context, rctx any, audio []byte, format string) error {
rc, ok := rctx.(replyContext)
if !ok {
return fmt.Errorf("telegram: SendAudio: invalid reply context type %T", rctx)
}
sendData := audio
sendFormat := strings.ToLower(strings.TrimSpace(format))
if sendFormat == "" {
sendFormat = "ogg"
}
switch sendFormat {
case "ogg", "opus", "mp3", "m4a":
// Attempt these formats directly with sendVoice first.
default:
converted, err := telegramConvertAudioToOpus(ctx, audio, sendFormat)
if err != nil {
return fmt.Errorf("telegram: SendAudio: convert %s to opus: %w", sendFormat, err)
}
sendData = converted
sendFormat = "opus"
}
if err := p.sendVoice(ctx, rc, sendData, sendFormat); err != nil {
if sendFormat == "mp3" || sendFormat == "m4a" {
if fallbackErr := p.sendAudio(ctx, rc, sendData, sendFormat); fallbackErr == nil {
return nil
} else {
return fmt.Errorf(
"telegram: SendAudio: %w",
errors.Join(
fmt.Errorf("sendVoice failed: %w", err),
fmt.Errorf("sendAudio fallback failed: %w", fallbackErr),
),
)
}View on GitHub (pinned to 4000b2338a)
Solutions
- Install ffmpeg (apt-get install ffmpeg / apk add ffmpeg) and verify it is on PATH
- Convert common formats (mp3/m4a) which skip conversion and use sendVoice directly, with sendAudio fallback
- Normalize input to wav/ogg at the synthesis step before calling SendAudio
- Validate the audio bytes are non-empty and correctly encoded
- Run the same ffmpeg command manually to see the raw codec error
Example fix
// before
p.SendAudio(ctx, rc, wavBytes, "wav") // requires ffmpeg
// after
// guard before calling
if _, err := exec.LookPath("ffmpeg"); err != nil {
return fmt.Errorf("audio conversion unavailable: install ffmpeg: %w", err)
}
p.SendAudio(ctx, rc, wavBytes, "wav") Defensive patterns
Strategy: fallback
Validate before calling
// guard conversion dependencies before calling
if _, err := exec.LookPath("ffmpeg"); err != nil {
return fmt.Errorf("ffmpeg required for %s audio: %w", format, err)
} Type guard
func needsOpusConversion(format string) bool {
switch strings.ToLower(strings.TrimSpace(format)) {
case "", "ogg", "opus", "mp3", "m4a":
return false
}
return true
} Try / catch
if err := p.SendAudio(ctx, rc, audio, "wav"); err != nil {
if strings.Contains(err.Error(), "convert") {
// fall back to mp3 or install ffmpeg
}
return err
} Prevention
- Install ffmpeg in the deployment image
- Emit TTS output as ogg/opus/mp3/m4a to skip conversion
- Validate audio bytes are non-empty and well-formed
- Test the conversion path in CI with ffmpeg present
When it happens
Trigger: Calling SendAudio with a format outside {ogg,opus,mp3,m4a} when ffmpeg is missing from PATH, exits non-zero, or the input bytes are corrupt/unsupported.
Common situations: Deploying in a slim container without ffmpeg installed; passing format strings like "wav" or "PCM"; truncated/corrupt audio buffers from the synthesizer; ffmpeg version lacking the libopus encoder.
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 in PATH: install ffmpeg to enable voice mes
- ffmpeg conversion failed: %w (stderr: %s)
- ffmpeg not found in PATH: install ffmpeg to enable audio con
- ffmpeg opus conversion failed: %w (stderr: %s)
- ffmpeg AMR conversion failed: %w (stderr: %s)
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/39f203f1a8433f6c.
Report an issue: GitHub.