{"record":{"id":"d7acfdd3cf698fda","repo":"iflytek/astron-agent","slug":"e","errorCode":null,"errorMessage":"音频转换失败: {e}","messagePattern":"音频转换失败: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"core/plugin/aitools/service/ise/ise_client.py","lineNumber":140,"sourceCode":"            else:\n                # Try to auto-detect the format.\n                audio = AudioSegment.from_file(io.BytesIO(audio_data))\n\n            # Convert the audio to the target format: 16kHz, 16bit, 1 channel.\n            audio = audio.set_frame_rate(16000)  # Set the sample rate to 16kHz.\n            audio = audio.set_sample_width(2)  # Set the sample width to 16bit.\n            audio = audio.set_channels(1)  # Set the number of channels to 1.\n\n            # Export the audio as WAV format.\n            wav_io = io.BytesIO()\n            audio.export(wav_io, format=\"wav\")\n            wav_data = wav_io.getvalue()\n            wav_io.close()\n\n            return wav_data, original_properties\n\n        except Exception as e:\n            raise ValueError(f\"音频转换失败: {e}\") from e\n\n    @staticmethod\n    def validate_audio_format(audio_data: bytes) -> Tuple[bool, str]:\n        \"\"\"Validate the audio format.\"\"\"\n        try:\n            format_type = AudioConverter.detect_audio_format(audio_data)\n            if format_type == \"wav\":\n                audio = AudioSegment.from_wav(io.BytesIO(audio_data))\n                if (\n                    audio.frame_rate == 16000\n                    and audio.sample_width == 2\n                    and audio.channels == 1\n                ):\n                    return True, \"音频格式符合要求\"\n                return (\n                    False,\n                    f\"WAV格式不符合要求: {audio.frame_rate}Hz,\\\n                            {audio.sample_width * 8}bit, {audio.channels}声道\",","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/plugin/aitools/service/ise/ise_client.py#L122-L158","documentation":"convert_to_wav raises ValueError('音频转换失败: ...') when any step of decoding the input audio and re-encoding it to WAV fails. This is a plain ValueError (not the service exception type), chained with `from e` to preserve the underlying cause (unsupported format, corrupt data, missing decoder).","triggerScenarios":"Calling convert_to_wav with bytes that AudioConverter cannot decode: corrupt/truncated audio, unsupported container/codec, empty input, or an ffmpeg/decoder environment problem.","commonSituations":"Users uploading exotic formats (e.g. AMR, opus in unusual containers), truncated uploads, wrong file extension vs real content, missing audio decoding library in the deployment image.","solutions":["Read the chained cause (`from e`) to see the exact decode failure.","Run detect_audio_format/validate_audio_format on the input before converting and reject unsupported formats early.","Verify the input file is complete and matches its declared format.","Ensure required audio codecs/ffmpeg are installed in the runtime image."],"exampleFix":"// before\nwav, props = AudioConverter.convert_to_wav(audio_bytes)\n\n// after\nok, fmt = AudioConverter.validate_audio_format(audio_bytes)\nif not ok:\n    raise HTTPException(400, f\"unsupported audio format: {fmt}\")\ntry:\n    wav, props = AudioConverter.convert_to_wav(audio_bytes)\nexcept ValueError as e:\n    raise HTTPException(400, str(e)) from e","handlingStrategy":"validation","validationCode":"ok, fmt = AudioConverter.validate_audio_format(audio_bytes)\nif not ok:\n    raise HTTPException(status_code=400, detail=f'unsupported audio: {fmt}')","typeGuard":null,"tryCatchPattern":"try:\n    wav, props = AudioConverter.convert_to_wav(audio_bytes)\nexcept ValueError as e:\n    logger.warning(f\"audio conversion failed: {e}\")\n    raise HTTPException(status_code=400, detail=str(e)) from e","preventionTips":["Run validate_audio_format before conversion","Reject truncated/empty uploads at ingestion","Install required codecs/ffmpeg in the runtime image","Catch ValueError specifically since this API raises ValueError, not ServiceException"],"tags":["audio","conversion","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}