-
Notifications
You must be signed in to change notification settings - Fork 741
Update documentation and fix docstrings #788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| .. _backend: | ||
|
|
||
| torchaudio.backend | ||
| ================== | ||
|
|
||
| :mod:`torchaudio.backend` module provides implementations for audio file I/O, using different backend libraries. | ||
| To switch backend, use :py:func:`torchaudio.set_audio_backend`. To check the current backend use :py:func:`torchaudio.get_audio_backend`. | ||
|
|
||
| .. warning:: | ||
| Although ``sox`` backend is default for backward compatibility reason, it has a number of issues, therefore it is highly recommended to use ``sox_io`` backend instead. Note, however, that due to the interface refinement, functions defined in ``sox`` backend and those defined in ``sox_io`` backend do not have the same signatures. | ||
|
|
||
| .. note:: | ||
| Instead of calling functions in :mod:`torchaudio.backend` directly, please use ``torchaudio.info``, ``torhcaudio.load``, ``torchaudio.load_wav`` and ``torchaudio.save`` with proper backend set with :func:`torchaudio.get_audio_backend`. | ||
|
|
||
| There are currently three implementations available. | ||
|
|
||
| * :ref:`sox<sox_backend>` | ||
| * :ref:`sox_io<sox_io_backend>` | ||
| * :ref:`soundfile<soundfile_backend>` | ||
|
|
||
| ``sox`` backend is the original backend which is built on ``libsox``. This module is currently default but is known to have number of issues, such as wrong handling of WAV files other than 16-bit signed integer. Users are encouraged to use ``sox_io`` backend. This backend requires C++ extension module and is not available on Windows system. | ||
|
|
||
| ``sox_io`` backend is the new backend which is built on ``libsox`` and bound to Python with ``Torchscript``. This module addresses all the known issues ``sox`` backend has. Function calls to this backend can be Torchscriptable. This backend requires C++ extension module and is not available on Windows system. | ||
|
|
||
| ``soundfile`` backend is built on ``PySoundFile``. You need to install ``PySoundFile`` separately. | ||
|
|
||
| Common Data Structure | ||
| ~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Structures used to exchange data between Python interface and ``libsox``. They are used by :ref:`sox<sox_backend>` and :ref:`soundfile<soundfile_backend>` but not by :ref:`sox_io<sox_io_backend>`. | ||
|
|
||
| .. autoclass:: torchaudio.backend.common.SignalInfo | ||
|
|
||
| .. autoclass:: torchaudio.backend.common.EncodingInfo | ||
|
|
||
| .. _sox_backend: | ||
|
|
||
| Sox Backend | ||
| ~~~~~~~~~~~ | ||
|
|
||
| ``sox`` backend is available on ``torchaudio`` installation with C++ extension. It is currently not available on Windows system. | ||
|
|
||
| It is currently default backend when it's available. You can switch from another backend to ``sox`` backend with the following; | ||
|
|
||
| .. code:: | ||
|
|
||
| torchaudio.set_audio_backend("sox") | ||
|
|
||
| info | ||
| ---- | ||
|
|
||
| .. autofunction:: torchaudio.backend.sox_backend.info | ||
|
|
||
| load | ||
| ---- | ||
|
|
||
| .. autofunction:: torchaudio.backend.sox_backend.load | ||
|
|
||
| .. autofunction:: torchaudio.backend.sox_backend.load_wav | ||
|
|
||
|
|
||
| save | ||
| ---- | ||
|
|
||
| .. autofunction:: torchaudio.backend.sox_backend.save | ||
|
|
||
| others | ||
| ------ | ||
|
|
||
| .. automodule:: torchaudio.backend.sox_backend | ||
| :members: | ||
| :exclude-members: info, load, load_wav, save | ||
|
|
||
| .. _sox_io_backend: | ||
|
|
||
| Sox IO Backend | ||
| ~~~~~~~~~~~~~~ | ||
|
|
||
| ``sox_io`` backend is available on ``torchaudio`` installation with C++ extension. It is currently not available on Windows system. | ||
|
|
||
| This new backend is recommended over ``sox`` backend. You can switch from another backend to ``sox_io`` backend with the following; | ||
|
|
||
| .. code:: | ||
|
|
||
| torchaudio.set_audio_backend("sox_io") | ||
|
|
||
| The function call to this backend can be Torchsript-able. You can apply :func:`torch.jit.script` and dump the object to file, then call it from C++ application. | ||
|
|
||
| info | ||
| ---- | ||
|
|
||
| .. autoclass:: torchaudio.backend.sox_io_backend.AudioMetaData | ||
|
|
||
| .. autofunction:: torchaudio.backend.sox_io_backend.info | ||
|
|
||
| load | ||
| ---- | ||
|
|
||
| .. autofunction:: torchaudio.backend.sox_io_backend.load | ||
|
|
||
| .. autofunction:: torchaudio.backend.sox_io_backend.load_wav | ||
|
|
||
|
|
||
| save | ||
| ---- | ||
|
|
||
| .. autofunction:: torchaudio.backend.sox_io_backend.save | ||
|
|
||
| .. _soundfile_backend: | ||
|
|
||
| Soundfile Backend | ||
| ~~~~~~~~~~~~~~~~~ | ||
|
|
||
| ``soundfile`` backend is available when ``PySoundFile`` is installed. This backend works on ``torchaudio`` installation without C++ extension. (i.e. Windows) | ||
|
|
||
| You can switch from another backend to ``soundfile`` backend with the following; | ||
|
|
||
| .. code:: | ||
|
|
||
| torchaudio.set_audio_backend("soundfile") | ||
|
|
||
| info | ||
| ---- | ||
|
|
||
| .. autofunction:: torchaudio.backend.soundfile_backend.info | ||
|
|
||
| load | ||
| ---- | ||
|
|
||
| .. autofunction:: torchaudio.backend.soundfile_backend.load | ||
|
|
||
| .. autofunction:: torchaudio.backend.soundfile_backend.load_wav | ||
|
|
||
|
|
||
| save | ||
| ---- | ||
|
|
||
| .. autofunction:: torchaudio.backend.soundfile_backend.save | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,19 @@ | ||
| torchaudio | ||
| =========== | ||
| ========== | ||
|
|
||
| The :mod:`torchaudio` package consists of I/O, popular datasets and common audio transformations. | ||
|
|
||
| .. toctree:: | ||
| :maxdepth: 2 | ||
| :caption: Package Reference | ||
|
|
||
| sox_effects | ||
| torchaudio | ||
| backend | ||
| functional | ||
| transforms | ||
| datasets | ||
| models | ||
| sox_effects | ||
| compliance.kaldi | ||
| kaldi_io | ||
| transforms | ||
| functional | ||
| utils | ||
|
|
||
| .. automodule:: torchaudio | ||
| :members: |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,52 @@ | ||
| .. role:: hidden | ||
| :class: hidden-section | ||
| .. _sox_effects: | ||
|
|
||
| torchaudio.sox_effects | ||
| ====================== | ||
|
|
||
| .. currentmodule:: torchaudio.sox_effects | ||
|
|
||
| .. warning:: | ||
|
|
||
| The :py:class:`SoxEffect` and :py:class:`SoxEffectsChain` classes are deprecated. Please migrate to :func:`apply_effects_tensor` and :func:`apply_effects_file`. | ||
|
|
||
| Resource initialization / shutdown | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| .. autofunction:: init_sox_effects | ||
|
|
||
| .. autofunction:: shutdown_sox_effects | ||
|
|
||
| Listing supported effects | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| .. autofunction:: effect_names | ||
|
|
||
| Applying effects | ||
| ~~~~~~~~~~~~~~~~ | ||
|
|
||
| Apply SoX effects chain on torch.Tensor or on file and load as torch.Tensor. | ||
|
|
||
| Applying effects on Tensor | ||
| -------------------------- | ||
|
|
||
| .. autofunction:: apply_effects_tensor | ||
|
|
||
| Applying effects on file | ||
| ------------------------ | ||
|
|
||
| .. autofunction:: apply_effects_file | ||
|
|
||
| Create SoX effects chain for preprocessing audio. | ||
| Legacy | ||
| ~~~~~~ | ||
|
|
||
| :hidden:`SoxEffect` | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| SoxEffect | ||
| --------- | ||
|
|
||
| .. autoclass:: SoxEffect | ||
| :members: | ||
|
|
||
| :hidden:`SoxEffectsChain` | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| SoxEffectsChain | ||
| --------------- | ||
|
|
||
| .. autoclass:: SoxEffectsChain | ||
| :members: append_effect_to_chain, sox_build_flow_effects, clear_chain, set_input_file |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| torchaudio | ||
| ========== | ||
|
|
||
| I/O functionalities | ||
| ~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Audio I/O functions are implemented in :ref:`torchaudio.backend<backend>` module, but for the ease of use, the following functions are made available on :mod:`torchaudio` module. There are different backends available and you can switch backends with :func:`set_audio_backend`. | ||
|
|
||
| Refer to :ref:`backend` for the detail. | ||
|
|
||
| .. function:: torchaudio.info(filepath: str, ...) | ||
|
|
||
| Fetch meta data of an audio file. Refer to :ref:`backend` for the detail. | ||
|
|
||
| .. function:: torchaudio.load(filepath: str, ...) | ||
|
|
||
| Load audio file into torch.Tensor object. Refer to :ref:`backend` for the detail. | ||
|
|
||
| .. function:: torchaudio.load_wav(filepath: str, ...) | ||
|
|
||
| Load audio file into torch.Tensor, Refer to :ref:`backend` for the detail. | ||
|
|
||
| .. function:: torchaudio.save(filepath: str, src: torch.Tensor, sample_rate: int, ...) | ||
|
|
||
| Save torch.Tensor object into an audio format. Refer to :ref:`backend` for the detail. | ||
|
|
||
| .. currentmodule:: torchaudio | ||
|
|
||
| Backend Utilities | ||
| ~~~~~~~~~~~~~~~~~ | ||
|
|
||
| .. autofunction:: list_audio_backends | ||
|
|
||
| .. autofunction:: get_audio_backend | ||
|
|
||
| .. autofunction:: set_audio_backend | ||
|
|
||
| Sox Effects Utilities | ||
| ~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| .. autofunction:: initialize_sox | ||
|
|
||
| .. autofunction:: shutdown_sox |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,11 @@ | ||
| .. role:: hidden | ||
| :class: hidden-section | ||
| torchaudio.utils | ||
| ================ | ||
|
|
||
| torchaudio.utils.sox_utils | ||
| ========================== | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Utility module to configure libsox. This affects functionalities in ``sox_io`` backend and ``torchaudio.sox_effects``. | ||
| Utility module to configure libsox. | ||
| This affects functionalities in :ref:`Sox IO backend<sox_io_backend>` and :ref:`Sox Effects<sox_effects>`. | ||
|
|
||
| .. currentmodule:: torchaudio.utils.sox_utils | ||
|
|
||
| .. autofunction:: set_seed | ||
|
|
||
| .. autofunction:: set_verbosity | ||
|
|
||
| .. autofunction:: set_buffer_size | ||
|
|
||
| .. autofunction:: set_use_threads | ||
|
|
||
| .. autofunction:: list_effects | ||
|
|
||
| .. autofunction:: list_formats | ||
| .. automodule:: torchaudio.utils.sox_utils | ||
| :members: |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, let's simplify the statement:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to do that after we figure out the plan for deprecation of
soxbackend.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My point is mostly to remove the idea of "issues", "interface refinement". How about this then?
Although
soxbackend is default for backward compatibility reason, it has a number of issues, therefore it is highly recommended to usesox_iobackend instead. Note, however, that due to the interface refinement, functions defined insoxbackend and those defined insox_iobackend do not have the signatures.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My point here is to discourage users to use
soxbackend and raise the awareness of the danger of using it. If we are not upfront of issues, users would not take efforts to migrate because it takes engineering efforts to do so.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate on "dangers"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it's summarized in #726
soxbackend does not load wav files other than 16-bit signed integer,savefunction does not preserve data,inforeturns the number of samples instead of the number of frames. This affects every aspect of ML application, from training to inference. There is always chance to introduce wrong data when usingloadand if one works on generative models,savefunction does not correctly save the data.Ideally we should fix it but the inconsistent design and band aides placed in a wrong place to fix the issue(load_wav), it's very difficult to do that now without breaking BC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification. I understand what you mean though I don't think this is the correct wording. Since I do not want to block this change here for this, I'll approve the pull request.