fix: convert mislabeled audio before STT#9329
Conversation
There was a problem hiding this comment.
Code Review
This pull request enhances the convert_audio_format function in astrbot/core/utils/media_utils.py to verify the actual audio format using _get_audio_magic_type rather than relying solely on the file extension, and adds a corresponding unit test. The reviewer correctly identified that calling _get_audio_magic_type synchronously inside an asynchronous function will block the asyncio event loop, and suggested offloading this operation to a separate thread using asyncio.to_thread.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Summary
.wavsuffix.wavfilenameRoot cause
MediaResolvercan materialize extensionless or base64 audio with the default.wavsuffix.ensure_wav()correctly detects that the bytes are not WAV and requests WAV conversion, butconvert_audio_format()previously returned early based only on the filename suffix. The unchanged non-RIFF payload was then rejected by the MiMo STT boundary validation.This change keeps the fast path only when both the suffix and detected audio format match the requested output format.
Follow-up to #9113 and #9118.
Validation
uv run pytest tests/test_media_utils.py -q -k "not test_file_uri_to_path_supports_localhost_and_encoded_paths"? 50 passed, 1 Windows-specific path test deselecteduv run pytest tests/test_mimo_api_sources.py -q? 19 passeduv run ruff check astrbot/core/utils/media_utils.py tests/test_media_utils.pyuv run ruff format --check astrbot/core/utils/media_utils.py tests/test_media_utils.py111responseSummary by Sourcery
Ensure audio format conversion validates the underlying magic bytes instead of relying solely on file extensions before speech-to-text processing.
Bug Fixes:
.wavsuffix to avoid STT boundary rejection.Tests:
ensure_wavconverts non-WAV AMR bytes stored under a.wavfilename and produces a valid RIFF/WAV output.