Skip to content

Commit d935be5

Browse files
committed
Undo accidental removal of sox_utils
1 parent 4c17ca4 commit d935be5

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed

src/torchaudio/utils/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from torio.utils import ffmpeg_utils
22

3+
from . import sox_utils
34
from .download import _download_asset
45

56

67
__all__ = [
8+
"sox_utils",
79
"ffmpeg_utils",
810
]

src/torchaudio/utils/sox_utils.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
"""Module to change the configuration of libsox, which is used by I/O functions like
2+
:py:mod:`~torchaudio.backend.sox_io_backend` and :py:mod:`~torchaudio.sox_effects`.
3+
4+
.. warning::
5+
Starting with version 2.8, we are refactoring TorchAudio to transition it
6+
into a maintenance phase. As a result:
7+
8+
- Some APIs are deprecated in 2.8 and will be removed in 2.9.
9+
- The decoding and encoding capabilities of PyTorch for both audio and video
10+
are being consolidated into TorchCodec.
11+
12+
Please see https://github.com/pytorch/audio/issues/3902 for more information.
13+
"""
14+
15+
from typing import Dict, List
16+
17+
import torchaudio
18+
19+
sox_ext = torchaudio._extension.lazy_import_sox_ext()
20+
21+
from torchaudio._internal.module_utils import dropping_support
22+
23+
@dropping_support
24+
def set_seed(seed: int):
25+
"""Set libsox's PRNG
26+
27+
Args:
28+
seed (int): seed value. valid range is int32.
29+
30+
See Also:
31+
http://sox.sourceforge.net/sox.html
32+
"""
33+
sox_ext.set_seed(seed)
34+
35+
36+
@dropping_support
37+
def set_verbosity(verbosity: int):
38+
"""Set libsox's verbosity
39+
40+
Args:
41+
verbosity (int): Set verbosity level of libsox.
42+
43+
* ``1`` failure messages
44+
* ``2`` warnings
45+
* ``3`` details of processing
46+
* ``4``-``6`` increasing levels of debug messages
47+
48+
See Also:
49+
http://sox.sourceforge.net/sox.html
50+
"""
51+
sox_ext.set_verbosity(verbosity)
52+
53+
54+
@dropping_support
55+
def set_buffer_size(buffer_size: int):
56+
"""Set buffer size for sox effect chain
57+
58+
Args:
59+
buffer_size (int): Set the size in bytes of the buffers used for processing audio.
60+
61+
See Also:
62+
http://sox.sourceforge.net/sox.html
63+
"""
64+
sox_ext.set_buffer_size(buffer_size)
65+
66+
67+
@dropping_support
68+
def set_use_threads(use_threads: bool):
69+
"""Set multithread option for sox effect chain
70+
71+
Args:
72+
use_threads (bool): When ``True``, enables ``libsox``'s parallel effects channels processing.
73+
To use mutlithread, the underlying ``libsox`` has to be compiled with OpenMP support.
74+
75+
See Also:
76+
http://sox.sourceforge.net/sox.html
77+
"""
78+
sox_ext.set_use_threads(use_threads)
79+
80+
81+
@dropping_support
82+
def list_effects() -> Dict[str, str]:
83+
"""List the available sox effect names
84+
85+
Returns:
86+
Dict[str, str]: Mapping from ``effect name`` to ``usage``
87+
"""
88+
return dict(sox_ext.list_effects())
89+
90+
91+
@dropping_support
92+
def list_read_formats() -> List[str]:
93+
"""List the supported audio formats for read
94+
95+
Returns:
96+
List[str]: List of supported audio formats
97+
"""
98+
return sox_ext.list_read_formats()
99+
100+
101+
@dropping_support
102+
def list_write_formats() -> List[str]:
103+
"""List the supported audio formats for write
104+
105+
Returns:
106+
List[str]: List of supported audio formats
107+
"""
108+
return sox_ext.list_write_formats()
109+
110+
111+
@dropping_support
112+
def get_buffer_size() -> int:
113+
"""Get buffer size for sox effect chain
114+
115+
Returns:
116+
int: size in bytes of buffers used for processing audio.
117+
"""
118+
return sox_ext.get_buffer_size()

0 commit comments

Comments
 (0)