read_audio fixes and docs cleanup #1592
Merged
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.
When using the
dictvariant ofread_audio, omitting the"stop"key would fail due to a breaking change in torchaudio0.8.0(SB currently requires any version newer than0.9.0).While this was undocumented, the code seemed to intend it as possible.
This PR does several things:
The function was cleaned up, with the call to
torchaudio.loadfixed, keeping backwards-compatibility.Added sanity checks, which raise an exception when the start-stop range seems incorrect. Let me know if these are overkill.
It attempts to improve the documentation for
read_audiosignificantly, documenting edge cases and previously undocumented behavior, namelyFollowing this PR, all of these now work:
Tests were added accordingly.
Root cause
Previously, the
num_framesparameter defaulted to0, which meant "load fromframe_offsetthrough the end of file".This is not the case anymore:
num_framesnow defaults to-1, with the same meaning. However, passing0now fails.Implementation details
In order to best match the past intended behavior, if
start == stop, this PR leaves thenum_framesparameter unspecified, which I feel is more intuitive than the previous code here.