{"record":{"id":"5aec4b113f8147c8","repo":"chenhg5/cc-connect","slug":"only-wav-format-can-be-compressed-got-s","errorCode":null,"errorMessage":"only WAV format can be compressed, got: %s","messagePattern":"only WAV format can be compressed, got: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/dingtalk/dingtalk.go","lineNumber":1301,"sourceCode":"\tdefer func() { _ = resp.Body.Close() }()\n\n\trespBody, _ := io.ReadAll(resp.Body)\n\tslog.Debug(\"dingtalk: oToMessages API response\", \"status\", resp.StatusCode, \"body\", string(respBody))\n\n\tif resp.StatusCode != 200 {\n\t\treturn fmt.Errorf(\"dingtalk: send audio failed: status=%d, body=%s\", resp.StatusCode, string(respBody))\n\t}\n\n\tslog.Info(\"dingtalk: voice message sent successfully\", \"media_id\", mediaID, \"conversation_id\", rc.conversationId)\n\treturn nil\n}\n\n// compressAudio compresses audio if it exceeds size limits.\n// Uses ffmpeg to convert WAV to MP3 format (DingTalk supported, ~10:1 compression ratio).\nfunc (p *Platform) compressAudio(ctx context.Context, audio []byte, format string) ([]byte, string, error) {\n\t// Only WAV format can be compressed to MP3\n\tif strings.ToLower(format) != \"wav\" {\n\t\treturn nil, \"\", fmt.Errorf(\"only WAV format can be compressed, got: %s\", format)\n\t}\n\n\treturn p.compressAudioWithFFmpeg(ctx, audio, format)\n}\n\n// compressAudioWithFFmpeg compresses audio using ffmpeg with stdin/stdout pipes.\n// Converts WAV to MP3 format (64 kbps for voice).\nfunc (p *Platform) compressAudioWithFFmpeg(ctx context.Context, audio []byte, format string) ([]byte, string, error) {\n\tffmpegPath, err := exec.LookPath(\"ffmpeg\")\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"ffmpeg not found: %w\", err)\n\t}\n\n\targs := []string{\n\t\t\"-i\", \"pipe:0\",\n\t\t\"-ar\", \"16000\", // 16kHz sample rate for voice\n\t\t\"-ac\", \"1\", // mono\n\t\t\"-b:a\", \"64k\", // 64 kbps bitrate (voice quality)","sourceCodeStart":1283,"sourceCodeEnd":1319,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/dingtalk/dingtalk.go#L1283-L1319","documentation":"compressAudio only supports converting WAV input (to MP3 via ffmpeg) to fit DingTalk's media size limits; any other input format is rejected with this error before ffmpeg is invoked. The library deliberately restricts compression to WAV because that is what the agent's TTS pipeline emits and what ffmpeg can reliably transcode here.","triggerScenarios":"Calling compressAudio (or the send-voice path that auto-compresses) with format set to anything other than \"wav\" (case-insensitive check), e.g. \"mp3\", \"ogg\", \"amr\".","commonSituations":"An upstream agent produced non-WAV TTS output; a format string like \".wav\" or \"audio/wav\" was passed instead of the bare \"wav\"; config switched TTS output format without updating the DingTalk path.","solutions":["Convert/transcode the audio to WAV before handing it to sendAudio/compressAudio.","Fix the format string passed in — it must be exactly \"wav\" (case is normalized, but not MIME types or extensions).","If the audio is already MP3 and small enough, skip compression and upload directly instead of routing through compressAudio."],"exampleFix":"// before\nreturn p.compressAudio(ctx, audio, \"audio/wav\")\n// after\nreturn p.compressAudio(ctx, audio, \"wav\")","handlingStrategy":"validation","validationCode":"func canCompress(format string) bool { return strings.ToLower(strings.TrimPrefix(format, \".\")) == \"wav\" }\nif !canCompress(format) && len(audio) > maxSize { return fmt.Errorf(\"cannot compress %s; convert to WAV first\", format) }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize format strings (strip dots, lowercase) at the pipeline boundary.","Configure the upstream TTS agent to emit WAV so compression is always possible.","If the audio is already a small MP3, bypass compression entirely."],"tags":["dingtalk","audio","validation","unsupported-format"],"backgroundTag":"unsupported-operation","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}