{"record":{"id":"38f6bb921e857826","repo":"agentscope-ai/agentscope","slug":"unsupported-audio-source-type-type-source-38f6bb","errorCode":null,"errorMessage":"Unsupported audio source type: {type(source)}.","messagePattern":"Unsupported audio source type: (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/agentscope/formatter/_openai_formatter.py","lineNumber":182,"sourceCode":"                # Local file\n                local_path = url_str.removeprefix(\"file://\")\n                with open(local_path, \"rb\") as f:\n                    data = base64.b64encode(f.read()).decode(\"utf-8\")\n            else:\n                # Remote URL — download and encode\n                response = requests.get(url_str, timeout=30)\n                response.raise_for_status()\n                data = base64.b64encode(response.content).decode(\"utf-8\")\n\n            return {\n                \"type\": \"input_audio\",\n                \"input_audio\": {\n                    \"data\": data,\n                    \"format\": audio_format,\n                },\n            }\n\n        raise TypeError(f\"Unsupported audio source type: {type(source)}.\")\n\n    @staticmethod\n    def _format_file_source(\n        source: URLSource | Base64Source,\n        name: str | None,\n    ) -> dict[str, Any]:\n        \"\"\"Convert a PDF source to the OpenAI ``file`` content part.\n\n        Files are always inlined as base64 data URIs: local ``file://`` URLs\n        are read from disk and remote URLs are downloaded, since the Chat\n        Completions API has no URL form for files.\n\n        Args:\n            source (`URLSource | Base64Source`):\n                The file source to convert.\n            name (`str | None`):\n                The file name presented to the API, falls back to\n                ``\"document.pdf\"``.","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/formatter/_openai_formatter.py#L164-L200","documentation":"After validating the media type, _format_audio_source handles Base64Source and URLSource; a source of any other type falls through to this TypeError. It mirrors the image/file source checks: OpenAI audio must be provided as base64 data or a URL.","triggerScenarios":"Passing an AudioBlock with a LocalFileSource or non-URL/base64 source (raw bytes, file object) to the OpenAI formatter.","commonSituations":"Recording audio locally and passing file paths; reusing audio blocks across providers; constructing sources manually instead of via the typed classes.","solutions":["Read the file, base64-encode it, and use Base64Source with media_type 'audio/wav' or 'audio/mpeg'","Or use URLSource with a hosted audio URL","Pre-validate audio sources before format() and fall back to text if unsupported"],"exampleFix":"# before\nAudioBlock(source=LocalFileSource(path=\"note.wav\"), alt=\"note\")\n\n# after\nimport base64\nAudioBlock(source=Base64Source(data=base64.b64encode(open(\"note.wav\",\"rb\").read()).decode(), media_type=\"audio/wav\"), alt=\"note\")","handlingStrategy":"type-guard","validationCode":"from agentscope.message import URLSource, Base64Source\nassert isinstance(source, (URLSource, Base64Source))","typeGuard":"def is_openai_audio_source(src) -> bool:\n    return isinstance(src, (URLSource, Base64Source))","tryCatchPattern":"try:\n    formatter.format(msgs)\nexcept TypeError as e:\n    if \"Unsupported audio source type\" in str(e):\n        block.source = to_base64_source(path, \"audio/wav\")\n        formatted = formatter.format(msgs)\n    else:\n        raise","preventionTips":["Never pass local file paths or file objects as audio sources","Keep a helper that reads and base64-encodes audio with the right media_type"],"tags":["openai","audio","multimodal","formatter","agentscope"],"backgroundTag":"unsupported-media-source-type","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}