Skip to content

Commit f55a67b

Browse files
committed
Update docs
1 parent 2d41e38 commit f55a67b

File tree

5 files changed

+48
-31
lines changed

5 files changed

+48
-31
lines changed

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The :mod:`torchaudio` package consists of I/O, popular datasets and common audio
1313
kaldi_io
1414
transforms
1515
functional
16+
utils
1617

1718
.. automodule:: torchaudio
1819
:members:

docs/source/sox_effects.rst

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,15 @@
44
torchaudio.sox_effects
55
======================
66

7-
Create SoX effects chain for preprocessing audio.
8-
97
.. currentmodule:: torchaudio.sox_effects
108

11-
:hidden:`apply_effects_tensor`
12-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9+
Apply SoX effects chain on torch.Tensor or on file and load as torch.Tensor.
1310

1411
.. autofunction:: apply_effects_tensor
1512

16-
:hidden:`apply_effects_file`
17-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18-
1913
.. autofunction:: apply_effects_file
2014

15+
Create SoX effects chain for preprocessing audio.
2116

2217
:hidden:`SoxEffect`
2318
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

docs/source/utils.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.. role:: hidden
2+
:class: hidden-section
3+
4+
torchaudio.utils.sox_utils
5+
==========================
6+
7+
Utility module to configure libsox. This affects functionalities in ``sox_io`` backend and ``torchaudio.sox_effects``.
8+
9+
.. currentmodule:: torchaudio.utils.sox_utils
10+
11+
.. autofunction:: set_seed
12+
13+
.. autofunction:: set_verbosity
14+
15+
.. autofunction:: set_buffer_size
16+
17+
.. autofunction:: set_use_threads
18+
19+
.. autofunction:: list_effects
20+
21+
.. autofunction:: list_formats

torchaudio/sox_effects/sox_effects.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ def apply_effects_tensor(
7979
the same channels order. The shape of the Tensor can be different based on the
8080
effects applied. Sample rate can also be different based on the effects applied.
8181
82+
Notes:
83+
This function works in the way very similar to ``sox`` command, however there are slight
84+
differences. For example, ``sox`` commnad adds certain effects automatically (such as
85+
``rate`` effect after ``speed`` and ``pitch`` and other effects), but this function does
86+
only applies the given effects. (Therefore, to actually apply ``speed`` effect, you also
87+
need to give ``rate`` effect with desired sampling rate.)
88+
8289
Examples:
8390
>>> # Defines the effects to apply
8491
>>> effects = [
@@ -98,7 +105,7 @@ def apply_effects_tensor(
98105
>>> # Apply effects
99106
>>> waveform, sample_rate = apply_effects_tensor(
100107
... wave_form, sample_rate, effects, channels_first=True)
101-
>>> # The new waveform his sampling rate 8000, 1 second.
108+
>>> # The new waveform is sampling rate 8000, 1 second.
102109
>>> # normalization and channel order are preserved
103110
>>> waveform.shape
104111
torch.Size([2, 8000])
@@ -107,13 +114,6 @@ def apply_effects_tensor(
107114
[ 0.1331, 0.0436, -0.3783, ..., -0.0035, 0.0012, 0.0008]])
108115
>>> sample_rate
109116
8000
110-
111-
Notes:
112-
This function works in the way very similar to ``sox`` command, however there are slight
113-
differences. For example, ``sox`` commnad adds certain effects automatically (such as
114-
``rate`` effect after ``speed`` and ``pitch`` and other effects), but this function does
115-
only applies the given effects. (Therefore, to actually apply ``speed`` effect, you also
116-
need to give ``rate`` effect with desired sampling rate.)
117117
"""
118118
in_signal = torch.classes.torchaudio.TensorSignal(tensor, sample_rate, channels_first)
119119
out_signal = torch.ops.torchaudio.sox_effects_apply_effects_tensor(in_signal, effects)
@@ -127,7 +127,7 @@ def apply_effects_file(
127127
normalize: bool = True,
128128
channels_first: bool = True,
129129
) -> Tuple[torch.Tensor, int]:
130-
"""Apply sox effects to the audio file and load Tensor
130+
"""Apply sox effects to the audio file and load the resulting data as Tensor
131131
132132
Args:
133133
path (str): Path to the audio file.
@@ -147,6 +147,14 @@ def apply_effects_file(
147147
If ``channels_first=True``, the resulting Tensor has dimension ``[channel, time]``,
148148
otherwise ``[time, channel]``.
149149
150+
Notes:
151+
This function works in the way very similar to ``sox`` command, however there are slight
152+
differences. For example, ``sox`` commnad adds certain effects automatically (such as
153+
``rate`` effect after ``speed``, ``pitch`` etc), but this function only applies the given
154+
effects. Therefore, to actually apply ``speed`` effect, you also need to give ``rate``
155+
effect with desired sampling rate, because internally, ``speed`` effects only alter sampling
156+
rate and leave samples untouched.
157+
150158
Examples:
151159
>>> # Defines the effects to apply
152160
>>> effects = [
@@ -165,14 +173,6 @@ def apply_effects_file(
165173
-5.6159e-07, 4.8103e-07]])
166174
>>> sample_rate
167175
8000
168-
169-
Notes:
170-
This function works in the way very similar to ``sox`` command, however there are slight
171-
differences. For example, ``sox`` commnad adds certain effects automatically (such as
172-
``rate`` effect after ``speed``, ``pitch`` etc), but this function only applies the given
173-
effects. Therefore, to actually apply ``speed`` effect, you also need to give ``rate``
174-
effect with desired sampling rate, because internally, ``speed`` effects only alter sampling
175-
rate and leave samples untouched.
176176
"""
177177
signal = torch.ops.torchaudio.sox_effects_apply_effects_file(path, effects, normalize, channels_first)
178178
return signal.get_tensor(), signal.get_sample_rate()

torchaudio/utils/sox_utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def set_seed(seed: int):
1212
"""Set libsox's PRNG
1313
1414
Args:
15-
seed: seed value. valid range is int32.
15+
seed (int): seed value. valid range is int32.
1616
1717
See Also:
1818
http://sox.sourceforge.net/sox.html
@@ -25,7 +25,7 @@ def set_verbosity(verbosity: int):
2525
"""Set libsox's verbosity
2626
2727
Args:
28-
verbosity: Set verbosity level of libsox.
28+
verbosity (int): Set verbosity level of libsox.
2929
1: failure messages
3030
2: warnings
3131
3: details of processing
@@ -42,7 +42,7 @@ def set_buffer_size(buffer_size: int):
4242
"""Set buffer size for sox effect chain
4343
4444
Args:
45-
buffer_size: Set the size in bytes of the buffers used for processing audio.
45+
buffer_size (int): Set the size in bytes of the buffers used for processing audio.
4646
4747
See Also:
4848
http://sox.sourceforge.net/sox.html
@@ -55,7 +55,7 @@ def set_use_threads(use_threads: bool):
5555
"""Set multithread option for sox effect chain
5656
5757
Args:
58-
use_threads: When True, enables libsox's parallel effects channels processing.
58+
use_threads (bool): When True, enables libsox's parallel effects channels processing.
5959
To use mutlithread, the underlying libsox has to be compiled with OpenMP support.
6060
6161
See Also:
@@ -69,7 +69,7 @@ def list_effects() -> Dict[str, str]:
6969
"""List the available sox effect names
7070
7171
Returns:
72-
Mapping from "effect name" to "usage"
72+
Dict[str, str]: Mapping from "effect name" to "usage"
7373
"""
7474
return dict(torch.ops.torchaudio.sox_utils_list_effects())
7575

@@ -78,7 +78,7 @@ def list_effects() -> Dict[str, str]:
7878
def list_formats() -> List[str]:
7979
"""List the supported audio formats
8080
81-
Returns: list[str]
82-
List of supported audio formats
81+
Returns:
82+
List[str]: List of supported audio formats
8383
"""
8484
return torch.ops.torchaudio.sox_utils_list_formats()

0 commit comments

Comments
 (0)