Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Use torchaudio for sox effects #16

Merged
merged 2 commits into from
Dec 2, 2020

Conversation

vincentqb
Copy link
Contributor

@vincentqb vincentqb commented Oct 28, 2020

As mentioned in #14, here's a pull request migrating WavAugment to torchaudio 0.7 :) This replaces the C++ backend with torchaudio.

  • Tested successfully on linux and macos. sox is not supported on windows.
  • The list of KNOWN_EFFECTS now includes {'fir'} and removes {'input', 'noisered', 'ladspa', 'output'} in this pull request.
  • torchaudio uses torchbinds (instead of pybind11), and so torchaudio.sox_effects.apply_effects_tensor is jitable.
python -m pytest -v --doctest-modules
=============================================================================================================== test session starts ================================================================================================================
platform linux -- Python 3.8.6, pytest-6.1.1, py-1.9.0, pluggy-0.13.1 -- /private/home/vincentqb/anaconda3/envs/wavaugment/bin/python
cachedir: .pytest_cache
rootdir: /private/home/vincentqb/WavAugment
collected 14 items                                                                                                                                                                                                                                 

augment/effects.py::augment.effects.EffectChain PASSED                                                                                                                                                                                       [  7%]
augment/effects.py::augment.effects.EffectChain.additive_noise PASSED                                                                                                                                                                        [ 14%]
augment/effects.py::augment.effects.EffectChain.clip PASSED                                                                                                                                                                                  [ 21%]
augment/effects.py::augment.effects.EffectChain.time_dropout PASSED                                                                                                                                                                          [ 28%]
augment/effects.py::augment.effects.SoxEffect.instantiate PASSED                                                                                                                                                                             [ 35%]
tests/augment_test.py::test_empty_chain PASSED                                                                                                                                                                                               [ 42%]
tests/augment_test.py::test_non_empty_chain PASSED                                                                                                                                                                                           [ 50%]
tests/augment_test.py::test_agains_cl PASSED                                                                                                                                                                                                 [ 57%]
tests/augment_test.py::test_stochastic_pitch PASSED                                                                                                                                                                                          [ 64%]
tests/augment_test.py::test_additive_noise PASSED                                                                                                                                                                                            [ 71%]
tests/augment_test.py::test_number_effects PASSED                                                                                                                                                                                            [ 78%]
tests/compare_to_sox_test.py::test_pitch PASSED                                                                                                                                                                                              [ 85%]
tests/compare_to_sox_test.py::test_reverb PASSED                                                                                                                                                                                             [ 92%]
tests/compare_to_sox_test.py::test_bandreject PASSED                                                                                                                                                                                         [100%]

================================================================================================================= warnings summary =================================================================================================================
../anaconda3/envs/wavaugment/lib/python3.8/site-packages/torchaudio/backend/utils.py:53
  /private/home/vincentqb/anaconda3/envs/wavaugment/lib/python3.8/site-packages/torchaudio/backend/utils.py:53: UserWarning: "sox" backend is being deprecated. The default backend will be changed to "sox_io" backend in 0.8.0 and "sox" backend will be removed in 0.9.0. Please migrate to "sox_io" backend. Please refer to https://github.com/pytorch/audio/issues/903 for the detail.
    warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/warnings.html
========================================================================================================== 14 passed, 1 warning in 1.34s ===========================================================================================================

Thoughts?

Closes #14

cc @eugene-kharitonov @astaff

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 28, 2020

def shutdown_sox() -> None:
_augment.shutdown_sox()
pass
Copy link
Contributor Author

@vincentqb vincentqb Oct 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

torchaudio now takes care of automatically initializing and shutting down sox. I kept it here to minimize the changes to the tests.

@vincentqb
Copy link
Contributor Author

BTW the warning simply means that torchaudio.set_audio_backend("sox_io") is the default on master and will be the default in the next release.

@eugene-kharitonov
Copy link
Contributor

Cool, thanks a lot @vincentqb ! I'll check this out in the next few days :)

@vincentqb vincentqb force-pushed the replacewithtorchaudio branch 2 times, most recently from f07245a to 772bcaf Compare October 28, 2020 18:51
@vincentqb
Copy link
Contributor Author

yay for the approval :)

@vincentqb vincentqb merged commit 27f5a0b into facebookresearch:master Dec 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate to torchaudio's sox implementation
3 participants