Handle non-UTF-8 metadata in audio file stream info#4174
Open
Mr-Neutr0n wants to merge 1 commit intopytorch:mainfrom
Open
Handle non-UTF-8 metadata in audio file stream info#4174Mr-Neutr0n wants to merge 1 commit intopytorch:mainfrom
Mr-Neutr0n wants to merge 1 commit intopytorch:mainfrom
Conversation
Some audio files (e.g. Opus files from the MLS dataset) contain metadata with non-UTF-8 bytes (such as Latin-1 encoded artist names), which causes a UnicodeDecodeError when the metadata is parsed during audio loading. This adds try/except guards around the AudioDecoder construction and the metadata.sample_rate access so that files with non-decodable metadata bytes produce a clear RuntimeError instead of an unhandled UnicodeDecodeError. Fixes pytorch#3821
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/audio/4174
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Merge Blocking SEVsThere is 1 active merge blocking SEVs. Please view them below:
If you must merge, use This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3821
Some audio files — particularly Opus files from the MLS dataset — contain
metadata with non-UTF-8 bytes (e.g. Latin-1 encoded artist/title tags with
byte
0xe9). This causes an unhandledUnicodeDecodeErrorwhentorchaudio.load()attempts to parse the stream metadata.This PR adds
try/except UnicodeDecodeErrorguards around:AudioDecoder(uri)construction — catches the error if the decoderfails during initialization due to non-decodable metadata bytes, and
re-raises as a clear
RuntimeError.decoder.metadata.sample_rateaccess — catches the error if metadataproperty access triggers the decode failure, falling back to
Noneso theexisting "unable to determine sample rate" error path is used.
Test plan
from MLS dataset) no longer raises
UnicodeDecodeErrorand insteadproduces a clear
RuntimeError