Repository navigation
FIX AudioSpeedConverter: document that pitch shifts with speed and reject empty output - #3814
Merged
Adrian Gavrila (adrian-gavrila) merged 3 commits intoNov 4, 2026
Conversation
…ject empty output The converter resamples the signal, so pitch changes together with speed (2x turns 440 Hz into 880 Hz), but the docstrings and the audio converter docs said pitch was preserved. Correct the docs, and raise a clear ValueError when the speed factor is so large that the output would have zero samples instead of silently writing empty audio. Fixes microsoft#3714 Signed-off-by: KVR Vishnu <46535652+VISHNU0906@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The two new async tests lack the _async naming suffix and parameter/return type annotations required by the style guide.
1 open issue
What changed in this PR
Addresses #3714 by aligning AudioSpeedConverter documentation with its resampling behavior and preventing empty audio output, without changing normal conversions.
Changes:
- Clarifies that pitch shifts with playback speed.
- Raises
ValueErrorwhen resampling would produce zero samples. - Adds regression tests for pitch shifting and short-input rejection.
| File | Description |
|---|---|
tests/unit/converter/test_audio_speed_converter.py |
Adds pitch-shift and empty-output regression tests. |
pyrit/converter/audio_speed_converter.py |
Corrects docstrings and rejects zero-sample output. |
doc/code/converters/2_audio_converters.py |
Updates documentation comments to describe pitch shifting. |
doc/code/converters/2_audio_converters.ipynb |
Mirrors the documentation corrections in the notebook. |
Review effort: Balanced
…dioSpeedConverter tests Signed-off-by: KVR Vishnu <46535652+VISHNU0906@users.noreply.github.com>
Adrian Gavrila (adrian-gavrila)
approved these changes
Nov 3, 2026
Adrian Gavrila (adrian-gavrila)
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the fix!
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.

Description
Fixes #3714.
AudioSpeedConverterchanges speed by resampling the samples, so the pitch moves together with the speed. A 440 Hz tone at 2x comes out at about 880 Hz. The class docstring, theconvert_asyncdocstring and the audio converters doc page all said pitch was preserved, which is not what the code does. The issue also showed that a very large factor on a short input silently writes a file with zero samples.The issue offered two routes: switch to a pitch-preserving time stretch, or correct the documented contract. I went with the smaller one here:
.pyand the paired notebook) now say the pitch shifts with the speed, with the 440 Hz to 880 Hz example_resample_audioraises a clearValueErrorwhen the factor would leave no samples, instead of writing empty audioBehaviour for normal inputs is unchanged. If you would rather have a real pitch-preserving stretch, I am happy to look at that as a follow-up instead.
cc Roman Lutz (@romanlutz) (issue author). Happy to adjust anything.
Tests and Documentation
Added two tests in
tests/unit/converter/test_audio_speed_converter.py:ValueErrorinstead of producing empty audio (fails on main, passes with the fix)Locally, on a fresh clone of main:
uv run pre-commit run --all-files: all hooks passedty check pyrit tests/unit(themake tytarget): all checks passedpytest -n 4 --dist=loadfile tests/unit): 32981 passed, 32 skippedDocs updated in
doc/code/converters/2_audio_converters.pyand.ipynb(two comment lines each).