torchaudio 2.7.1__cp311-cp311-win_amd64.whl → 2.9.0__cp311-cp311-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of torchaudio might be problematic. Click here for more details.

Files changed (92) hide show
  1. torchaudio/__init__.py +184 -33
  2. torchaudio/_extension/__init__.py +1 -14
  3. torchaudio/_extension/utils.py +0 -47
  4. torchaudio/_internal/module_utils.py +68 -10
  5. torchaudio/_torchcodec.py +340 -0
  6. torchaudio/datasets/cmuarctic.py +1 -1
  7. torchaudio/datasets/utils.py +1 -1
  8. torchaudio/functional/__init__.py +6 -3
  9. torchaudio/functional/_alignment.py +1 -1
  10. torchaudio/functional/filtering.py +70 -55
  11. torchaudio/functional/functional.py +31 -61
  12. torchaudio/lib/_torchaudio.pyd +0 -0
  13. torchaudio/lib/libtorchaudio.pyd +0 -0
  14. torchaudio/models/decoder/__init__.py +19 -1
  15. torchaudio/models/decoder/_ctc_decoder.py +6 -6
  16. torchaudio/models/decoder/_cuda_ctc_decoder.py +1 -1
  17. torchaudio/models/squim/objective.py +2 -2
  18. torchaudio/pipelines/_source_separation_pipeline.py +1 -1
  19. torchaudio/pipelines/_squim_pipeline.py +2 -2
  20. torchaudio/pipelines/_tts/utils.py +3 -1
  21. torchaudio/pipelines/rnnt_pipeline.py +4 -4
  22. torchaudio/transforms/__init__.py +4 -1
  23. torchaudio/transforms/_transforms.py +4 -3
  24. torchaudio/utils/__init__.py +2 -9
  25. torchaudio/utils/download.py +1 -1
  26. torchaudio/version.py +2 -2
  27. {torchaudio-2.7.1.dist-info → torchaudio-2.9.0.dist-info}/METADATA +15 -7
  28. torchaudio-2.9.0.dist-info/RECORD +85 -0
  29. {torchaudio-2.7.1.dist-info → torchaudio-2.9.0.dist-info}/top_level.txt +0 -1
  30. torchaudio/_backend/__init__.py +0 -61
  31. torchaudio/_backend/backend.py +0 -53
  32. torchaudio/_backend/common.py +0 -52
  33. torchaudio/_backend/ffmpeg.py +0 -334
  34. torchaudio/_backend/soundfile.py +0 -54
  35. torchaudio/_backend/soundfile_backend.py +0 -457
  36. torchaudio/_backend/sox.py +0 -91
  37. torchaudio/_backend/utils.py +0 -317
  38. torchaudio/backend/__init__.py +0 -8
  39. torchaudio/backend/_no_backend.py +0 -25
  40. torchaudio/backend/_sox_io_backend.py +0 -294
  41. torchaudio/backend/common.py +0 -13
  42. torchaudio/backend/no_backend.py +0 -14
  43. torchaudio/backend/soundfile_backend.py +0 -14
  44. torchaudio/backend/sox_io_backend.py +0 -14
  45. torchaudio/io/__init__.py +0 -13
  46. torchaudio/io/_effector.py +0 -347
  47. torchaudio/io/_playback.py +0 -72
  48. torchaudio/kaldi_io.py +0 -144
  49. torchaudio/prototype/__init__.py +0 -0
  50. torchaudio/prototype/datasets/__init__.py +0 -4
  51. torchaudio/prototype/datasets/musan.py +0 -67
  52. torchaudio/prototype/functional/__init__.py +0 -26
  53. torchaudio/prototype/functional/_dsp.py +0 -433
  54. torchaudio/prototype/functional/_rir.py +0 -379
  55. torchaudio/prototype/functional/functional.py +0 -190
  56. torchaudio/prototype/models/__init__.py +0 -36
  57. torchaudio/prototype/models/_conformer_wav2vec2.py +0 -794
  58. torchaudio/prototype/models/_emformer_hubert.py +0 -333
  59. torchaudio/prototype/models/conv_emformer.py +0 -525
  60. torchaudio/prototype/models/hifi_gan.py +0 -336
  61. torchaudio/prototype/models/rnnt.py +0 -711
  62. torchaudio/prototype/models/rnnt_decoder.py +0 -399
  63. torchaudio/prototype/pipelines/__init__.py +0 -12
  64. torchaudio/prototype/pipelines/_vggish/__init__.py +0 -3
  65. torchaudio/prototype/pipelines/_vggish/_vggish_impl.py +0 -233
  66. torchaudio/prototype/pipelines/_vggish/_vggish_pipeline.py +0 -82
  67. torchaudio/prototype/pipelines/hifigan_pipeline.py +0 -228
  68. torchaudio/prototype/pipelines/rnnt_pipeline.py +0 -58
  69. torchaudio/prototype/transforms/__init__.py +0 -9
  70. torchaudio/prototype/transforms/_transforms.py +0 -456
  71. torchaudio/sox_effects/__init__.py +0 -10
  72. torchaudio/sox_effects/sox_effects.py +0 -272
  73. torchaudio/utils/ffmpeg_utils.py +0 -11
  74. torchaudio/utils/sox_utils.py +0 -99
  75. torchaudio-2.7.1.dist-info/RECORD +0 -144
  76. torio/__init__.py +0 -8
  77. torio/_extension/__init__.py +0 -13
  78. torio/_extension/utils.py +0 -147
  79. torio/io/__init__.py +0 -9
  80. torio/io/_streaming_media_decoder.py +0 -978
  81. torio/io/_streaming_media_encoder.py +0 -502
  82. torio/lib/__init__.py +0 -0
  83. torio/lib/_torio_ffmpeg4.pyd +0 -0
  84. torio/lib/_torio_ffmpeg5.pyd +0 -0
  85. torio/lib/_torio_ffmpeg6.pyd +0 -0
  86. torio/lib/libtorio_ffmpeg4.pyd +0 -0
  87. torio/lib/libtorio_ffmpeg5.pyd +0 -0
  88. torio/lib/libtorio_ffmpeg6.pyd +0 -0
  89. torio/utils/__init__.py +0 -4
  90. torio/utils/ffmpeg_utils.py +0 -247
  91. {torchaudio-2.7.1.dist-info → torchaudio-2.9.0.dist-info}/WHEEL +0 -0
  92. {torchaudio-2.7.1.dist-info → torchaudio-2.9.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,317 +0,0 @@
1
- import os
2
- from functools import lru_cache
3
- from typing import BinaryIO, Dict, Optional, Tuple, Type, Union
4
-
5
- import torch
6
-
7
- from torchaudio._extension import lazy_import_sox_ext
8
- from torchaudio.io import CodecConfig
9
- from torio._extension import lazy_import_ffmpeg_ext
10
-
11
- from . import soundfile_backend
12
-
13
- from .backend import Backend
14
- from .common import AudioMetaData
15
- from .ffmpeg import FFmpegBackend
16
- from .soundfile import SoundfileBackend
17
- from .sox import SoXBackend
18
-
19
-
20
- @lru_cache(None)
21
- def get_available_backends() -> Dict[str, Type[Backend]]:
22
- backend_specs: Dict[str, Type[Backend]] = {}
23
- if lazy_import_ffmpeg_ext().is_available():
24
- backend_specs["ffmpeg"] = FFmpegBackend
25
- if lazy_import_sox_ext().is_available():
26
- backend_specs["sox"] = SoXBackend
27
- if soundfile_backend._IS_SOUNDFILE_AVAILABLE:
28
- backend_specs["soundfile"] = SoundfileBackend
29
- return backend_specs
30
-
31
-
32
- def get_backend(backend_name, backends) -> Backend:
33
- if backend := backends.get(backend_name):
34
- return backend
35
- else:
36
- raise ValueError(
37
- f"Unsupported backend '{backend_name}' specified; ",
38
- f"please select one of {list(backends.keys())} instead.",
39
- )
40
-
41
-
42
- def get_info_func():
43
- backends = get_available_backends()
44
-
45
- def dispatcher(
46
- uri: Union[BinaryIO, str, os.PathLike], format: Optional[str], backend_name: Optional[str]
47
- ) -> Backend:
48
- if backend_name is not None:
49
- return get_backend(backend_name, backends)
50
-
51
- for backend in backends.values():
52
- if backend.can_decode(uri, format):
53
- return backend
54
- raise RuntimeError(f"Couldn't find appropriate backend to handle uri {uri} and format {format}.")
55
-
56
- def info(
57
- uri: Union[BinaryIO, str, os.PathLike],
58
- format: Optional[str] = None,
59
- buffer_size: int = 4096,
60
- backend: Optional[str] = None,
61
- ) -> AudioMetaData:
62
- """Get signal information of an audio file.
63
-
64
- Note:
65
- When the input type is file-like object, this function cannot
66
- get the correct length (``num_samples``) for certain formats,
67
- such as ``vorbis``.
68
- In this case, the value of ``num_samples`` is ``0``.
69
-
70
- Args:
71
- uri (path-like object or file-like object):
72
- Source of audio data. The following types are accepted:
73
-
74
- * ``path-like``: File path or URL.
75
- * ``file-like``: Object with ``read(size: int) -> bytes`` method,
76
- which returns byte string of at most ``size`` length.
77
-
78
- format (str or None, optional):
79
- If not ``None``, interpreted as hint that may allow backend to override the detected format.
80
- (Default: ``None``)
81
-
82
- buffer_size (int, optional):
83
- Size of buffer to use when processing file-like objects, in bytes. (Default: ``4096``)
84
-
85
- backend (str or None, optional):
86
- I/O backend to use.
87
- If ``None``, function selects backend given input and available backends.
88
- Otherwise, must be one of [``"ffmpeg"``, ``"sox"``, ``"soundfile"``],
89
- with the corresponding backend available.
90
- (Default: ``None``)
91
-
92
- .. seealso::
93
- :ref:`backend`
94
-
95
- Returns:
96
- AudioMetaData
97
- """
98
- backend = dispatcher(uri, format, backend)
99
- return backend.info(uri, format, buffer_size)
100
-
101
- return info
102
-
103
-
104
- def get_load_func():
105
- backends = get_available_backends()
106
-
107
- def dispatcher(
108
- uri: Union[BinaryIO, str, os.PathLike], format: Optional[str], backend_name: Optional[str]
109
- ) -> Backend:
110
- if backend_name is not None:
111
- return get_backend(backend_name, backends)
112
-
113
- for backend in backends.values():
114
- if backend.can_decode(uri, format):
115
- return backend
116
- raise RuntimeError(f"Couldn't find appropriate backend to handle uri {uri} and format {format}.")
117
-
118
- def load(
119
- uri: Union[BinaryIO, str, os.PathLike],
120
- frame_offset: int = 0,
121
- num_frames: int = -1,
122
- normalize: bool = True,
123
- channels_first: bool = True,
124
- format: Optional[str] = None,
125
- buffer_size: int = 4096,
126
- backend: Optional[str] = None,
127
- ) -> Tuple[torch.Tensor, int]:
128
- """Load audio data from source.
129
-
130
- By default (``normalize=True``, ``channels_first=True``), this function returns Tensor with
131
- ``float32`` dtype, and the shape of `[channel, time]`.
132
-
133
- Note:
134
- The formats this function can handle depend on the availability of backends.
135
- Please use the following functions to fetch the supported formats.
136
-
137
- - FFmpeg: :py:func:`torchaudio.utils.ffmpeg_utils.get_audio_decoders`
138
- - Sox: :py:func:`torchaudio.utils.sox_utils.list_read_formats`
139
- - SoundFile: Refer to `the official document <https://pysoundfile.readthedocs.io/>`__.
140
-
141
- .. warning::
142
-
143
- ``normalize`` argument does not perform volume normalization.
144
- It only converts the sample type to `torch.float32` from the native sample
145
- type.
146
-
147
- When the input format is WAV with integer type, such as 32-bit signed integer, 16-bit
148
- signed integer, 24-bit signed integer, and 8-bit unsigned integer, by providing ``normalize=False``,
149
- this function can return integer Tensor, where the samples are expressed within the whole range
150
- of the corresponding dtype, that is, ``int32`` tensor for 32-bit signed PCM,
151
- ``int16`` for 16-bit signed PCM and ``uint8`` for 8-bit unsigned PCM. Since torch does not
152
- support ``int24`` dtype, 24-bit signed PCM are converted to ``int32`` tensors.
153
-
154
- ``normalize`` argument has no effect on 32-bit floating-point WAV and other formats, such as
155
- ``flac`` and ``mp3``.
156
-
157
- For these formats, this function always returns ``float32`` Tensor with values.
158
-
159
-
160
- Args:
161
- uri (path-like object or file-like object):
162
- Source of audio data.
163
- frame_offset (int, optional):
164
- Number of frames to skip before start reading data.
165
- num_frames (int, optional):
166
- Maximum number of frames to read. ``-1`` reads all the remaining samples,
167
- starting from ``frame_offset``.
168
- This function may return the less number of frames if there is not enough
169
- frames in the given file.
170
- normalize (bool, optional):
171
- When ``True``, this function converts the native sample type to ``float32``.
172
- Default: ``True``.
173
-
174
- If input file is integer WAV, giving ``False`` will change the resulting Tensor type to
175
- integer type.
176
- This argument has no effect for formats other than integer WAV type.
177
-
178
- channels_first (bool, optional):
179
- When True, the returned Tensor has dimension `[channel, time]`.
180
- Otherwise, the returned Tensor's dimension is `[time, channel]`.
181
-
182
- format (str or None, optional):
183
- If not ``None``, interpreted as hint that may allow backend to override the detected format.
184
- (Default: ``None``)
185
-
186
- buffer_size (int, optional):
187
- Size of buffer to use when processing file-like objects, in bytes. (Default: ``4096``)
188
-
189
- backend (str or None, optional):
190
- I/O backend to use.
191
- If ``None``, function selects backend given input and available backends.
192
- Otherwise, must be one of [``"ffmpeg"``, ``"sox"``, ``"soundfile"``],
193
- with the corresponding backend being available. (Default: ``None``)
194
-
195
- .. seealso::
196
- :ref:`backend`
197
-
198
- Returns:
199
- (torch.Tensor, int): Resulting Tensor and sample rate.
200
- If the input file has integer wav format and normalization is off, then it has
201
- integer type, else ``float32`` type. If ``channels_first=True``, it has
202
- `[channel, time]` else `[time, channel]`.
203
- """
204
- backend = dispatcher(uri, format, backend)
205
- return backend.load(uri, frame_offset, num_frames, normalize, channels_first, format, buffer_size)
206
-
207
- return load
208
-
209
-
210
- def get_save_func():
211
- backends = get_available_backends()
212
-
213
- def dispatcher(
214
- uri: Union[BinaryIO, str, os.PathLike], format: Optional[str], backend_name: Optional[str]
215
- ) -> Backend:
216
- if backend_name is not None:
217
- return get_backend(backend_name, backends)
218
-
219
- for backend in backends.values():
220
- if backend.can_encode(uri, format):
221
- return backend
222
- raise RuntimeError(f"Couldn't find appropriate backend to handle uri {uri} and format {format}.")
223
-
224
- def save(
225
- uri: Union[BinaryIO, str, os.PathLike],
226
- src: torch.Tensor,
227
- sample_rate: int,
228
- channels_first: bool = True,
229
- format: Optional[str] = None,
230
- encoding: Optional[str] = None,
231
- bits_per_sample: Optional[int] = None,
232
- buffer_size: int = 4096,
233
- backend: Optional[str] = None,
234
- compression: Optional[Union[CodecConfig, float, int]] = None,
235
- ):
236
- """Save audio data to file.
237
-
238
- Note:
239
- The formats this function can handle depend on the availability of backends.
240
- Please use the following functions to fetch the supported formats.
241
-
242
- - FFmpeg: :py:func:`torchaudio.utils.ffmpeg_utils.get_audio_encoders`
243
- - Sox: :py:func:`torchaudio.utils.sox_utils.list_write_formats`
244
- - SoundFile: Refer to `the official document <https://pysoundfile.readthedocs.io/>`__.
245
-
246
- Args:
247
- uri (str or pathlib.Path): Path to audio file.
248
- src (torch.Tensor): Audio data to save. must be 2D tensor.
249
- sample_rate (int): sampling rate
250
- channels_first (bool, optional): If ``True``, the given tensor is interpreted as `[channel, time]`,
251
- otherwise `[time, channel]`.
252
- format (str or None, optional): Override the audio format.
253
- When ``uri`` argument is path-like object, audio format is
254
- inferred from file extension. If the file extension is missing or
255
- different, you can specify the correct format with this argument.
256
-
257
- When ``uri`` argument is file-like object,
258
- this argument is required.
259
-
260
- Valid values are ``"wav"``, ``"ogg"``, and ``"flac"``.
261
- encoding (str or None, optional): Changes the encoding for supported formats.
262
- This argument is effective only for supported formats, i.e.
263
- ``"wav"`` and ``""flac"```. Valid values are
264
-
265
- - ``"PCM_S"`` (signed integer Linear PCM)
266
- - ``"PCM_U"`` (unsigned integer Linear PCM)
267
- - ``"PCM_F"`` (floating point PCM)
268
- - ``"ULAW"`` (mu-law)
269
- - ``"ALAW"`` (a-law)
270
-
271
- bits_per_sample (int or None, optional): Changes the bit depth for the
272
- supported formats.
273
- When ``format`` is one of ``"wav"`` and ``"flac"``,
274
- you can change the bit depth.
275
- Valid values are ``8``, ``16``, ``24``, ``32`` and ``64``.
276
-
277
- buffer_size (int, optional):
278
- Size of buffer to use when processing file-like objects, in bytes. (Default: ``4096``)
279
-
280
- backend (str or None, optional):
281
- I/O backend to use.
282
- If ``None``, function selects backend given input and available backends.
283
- Otherwise, must be one of [``"ffmpeg"``, ``"sox"``, ``"soundfile"``],
284
- with the corresponding backend being available.
285
- (Default: ``None``)
286
-
287
- .. seealso::
288
- :ref:`backend`
289
-
290
- compression (CodecConfig, float, int, or None, optional):
291
- Compression configuration to apply.
292
-
293
- If the selected backend is FFmpeg, an instance of :py:class:`CodecConfig` must be provided.
294
-
295
- Otherwise, if the selected backend is SoX, a float or int value corresponding to option ``-C`` of the
296
- ``sox`` command line interface must be provided. For instance:
297
-
298
- ``"mp3"``
299
- Either bitrate (in ``kbps``) with quality factor, such as ``128.2``, or
300
- VBR encoding with quality factor such as ``-4.2``. Default: ``-4.5``.
301
-
302
- ``"flac"``
303
- Whole number from ``0`` to ``8``. ``8`` is default and highest compression.
304
-
305
- ``"ogg"``, ``"vorbis"``
306
- Number from ``-1`` to ``10``; ``-1`` is the highest compression
307
- and lowest quality. Default: ``3``.
308
-
309
- Refer to http://sox.sourceforge.net/soxformat.html for more details.
310
-
311
- """
312
- backend = dispatcher(uri, format, backend)
313
- return backend.save(
314
- uri, src, sample_rate, channels_first, format, encoding, bits_per_sample, buffer_size, compression
315
- )
316
-
317
- return save
@@ -1,8 +0,0 @@
1
- # NOTE:
2
- # The entire `torchaudio.backend` module is deprecated.
3
- # New things should be added to `torchaudio._backend`.
4
- # Only things related to backward compatibility should be placed here.
5
-
6
- from . import common, no_backend, soundfile_backend, sox_io_backend # noqa
7
-
8
- __all__ = []
@@ -1,25 +0,0 @@
1
- from pathlib import Path
2
- from typing import Callable, Optional, Tuple, Union
3
-
4
- from torch import Tensor
5
- from torchaudio import AudioMetaData
6
-
7
-
8
- def load(
9
- filepath: Union[str, Path],
10
- out: Optional[Tensor] = None,
11
- normalization: Union[bool, float, Callable] = True,
12
- channels_first: bool = True,
13
- num_frames: int = 0,
14
- offset: int = 0,
15
- filetype: Optional[str] = None,
16
- ) -> Tuple[Tensor, int]:
17
- raise RuntimeError("No audio I/O backend is available.")
18
-
19
-
20
- def save(filepath: str, src: Tensor, sample_rate: int, precision: int = 16, channels_first: bool = True) -> None:
21
- raise RuntimeError("No audio I/O backend is available.")
22
-
23
-
24
- def info(filepath: str) -> AudioMetaData:
25
- raise RuntimeError("No audio I/O backend is available.")
@@ -1,294 +0,0 @@
1
- import os
2
- from typing import Optional, Tuple
3
-
4
- import torch
5
- import torchaudio
6
- from torchaudio import AudioMetaData
7
-
8
- sox_ext = torchaudio._extension.lazy_import_sox_ext()
9
-
10
-
11
- def info(
12
- filepath: str,
13
- format: Optional[str] = None,
14
- ) -> AudioMetaData:
15
- """Get signal information of an audio file.
16
-
17
- Args:
18
- filepath (str):
19
- Source of audio data.
20
-
21
- format (str or None, optional):
22
- Override the format detection with the given format.
23
- Providing the argument might help when libsox can not infer the format
24
- from header or extension.
25
-
26
- Returns:
27
- AudioMetaData: Metadata of the given audio.
28
- """
29
- if not torch.jit.is_scripting():
30
- if hasattr(filepath, "read"):
31
- raise RuntimeError("sox_io backend does not support file-like object.")
32
- filepath = os.fspath(filepath)
33
- sinfo = sox_ext.get_info(filepath, format)
34
- return AudioMetaData(*sinfo)
35
-
36
-
37
- def load(
38
- filepath: str,
39
- frame_offset: int = 0,
40
- num_frames: int = -1,
41
- normalize: bool = True,
42
- channels_first: bool = True,
43
- format: Optional[str] = None,
44
- ) -> Tuple[torch.Tensor, int]:
45
- """Load audio data from file.
46
-
47
- Note:
48
- This function can handle all the codecs that underlying libsox can handle,
49
- however it is tested on the following formats;
50
-
51
- * WAV, AMB
52
-
53
- * 32-bit floating-point
54
- * 32-bit signed integer
55
- * 24-bit signed integer
56
- * 16-bit signed integer
57
- * 8-bit unsigned integer (WAV only)
58
-
59
- * MP3
60
- * FLAC
61
- * OGG/VORBIS
62
- * OPUS
63
- * SPHERE
64
- * AMR-NB
65
-
66
- To load ``MP3``, ``FLAC``, ``OGG/VORBIS``, ``OPUS`` and other codecs ``libsox`` does not
67
- handle natively, your installation of ``torchaudio`` has to be linked to ``libsox``
68
- and corresponding codec libraries such as ``libmad`` or ``libmp3lame`` etc.
69
-
70
- By default (``normalize=True``, ``channels_first=True``), this function returns Tensor with
71
- ``float32`` dtype, and the shape of `[channel, time]`.
72
-
73
- .. warning::
74
-
75
- ``normalize`` argument does not perform volume normalization.
76
- It only converts the sample type to `torch.float32` from the native sample
77
- type.
78
-
79
- When the input format is WAV with integer type, such as 32-bit signed integer, 16-bit
80
- signed integer, 24-bit signed integer, and 8-bit unsigned integer, by providing ``normalize=False``,
81
- this function can return integer Tensor, where the samples are expressed within the whole range
82
- of the corresponding dtype, that is, ``int32`` tensor for 32-bit signed PCM,
83
- ``int16`` for 16-bit signed PCM and ``uint8`` for 8-bit unsigned PCM. Since torch does not
84
- support ``int24`` dtype, 24-bit signed PCM are converted to ``int32`` tensors.
85
-
86
- ``normalize`` argument has no effect on 32-bit floating-point WAV and other formats, such as
87
- ``flac`` and ``mp3``.
88
-
89
- For these formats, this function always returns ``float32`` Tensor with values.
90
-
91
- Args:
92
- filepath (path-like object): Source of audio data.
93
- frame_offset (int):
94
- Number of frames to skip before start reading data.
95
- num_frames (int, optional):
96
- Maximum number of frames to read. ``-1`` reads all the remaining samples,
97
- starting from ``frame_offset``.
98
- This function may return the less number of frames if there is not enough
99
- frames in the given file.
100
- normalize (bool, optional):
101
- When ``True``, this function converts the native sample type to ``float32``.
102
- Default: ``True``.
103
-
104
- If input file is integer WAV, giving ``False`` will change the resulting Tensor type to
105
- integer type.
106
- This argument has no effect for formats other than integer WAV type.
107
-
108
- channels_first (bool, optional):
109
- When True, the returned Tensor has dimension `[channel, time]`.
110
- Otherwise, the returned Tensor's dimension is `[time, channel]`.
111
- format (str or None, optional):
112
- Override the format detection with the given format.
113
- Providing the argument might help when libsox can not infer the format
114
- from header or extension.
115
-
116
- Returns:
117
- (torch.Tensor, int): Resulting Tensor and sample rate.
118
- If the input file has integer wav format and ``normalize=False``, then it has
119
- integer type, else ``float32`` type. If ``channels_first=True``, it has
120
- `[channel, time]` else `[time, channel]`.
121
- """
122
- if not torch.jit.is_scripting():
123
- if hasattr(filepath, "read"):
124
- raise RuntimeError("sox_io backend does not support file-like object.")
125
- filepath = os.fspath(filepath)
126
- return sox_ext.load_audio_file(filepath, frame_offset, num_frames, normalize, channels_first, format)
127
-
128
-
129
- def save(
130
- filepath: str,
131
- src: torch.Tensor,
132
- sample_rate: int,
133
- channels_first: bool = True,
134
- compression: Optional[float] = None,
135
- format: Optional[str] = None,
136
- encoding: Optional[str] = None,
137
- bits_per_sample: Optional[int] = None,
138
- ):
139
- """Save audio data to file.
140
-
141
- Args:
142
- filepath (path-like object): Path to save file.
143
- src (torch.Tensor): Audio data to save. must be 2D tensor.
144
- sample_rate (int): sampling rate
145
- channels_first (bool, optional): If ``True``, the given tensor is interpreted as `[channel, time]`,
146
- otherwise `[time, channel]`.
147
- compression (float or None, optional): Used for formats other than WAV.
148
- This corresponds to ``-C`` option of ``sox`` command.
149
-
150
- ``"mp3"``
151
- Either bitrate (in ``kbps``) with quality factor, such as ``128.2``, or
152
- VBR encoding with quality factor such as ``-4.2``. Default: ``-4.5``.
153
-
154
- ``"flac"``
155
- Whole number from ``0`` to ``8``. ``8`` is default and highest compression.
156
-
157
- ``"ogg"``, ``"vorbis"``
158
- Number from ``-1`` to ``10``; ``-1`` is the highest compression
159
- and lowest quality. Default: ``3``.
160
-
161
- See the detail at http://sox.sourceforge.net/soxformat.html.
162
- format (str or None, optional): Override the audio format.
163
- When ``filepath`` argument is path-like object, audio format is infered from
164
- file extension. If file extension is missing or different, you can specify the
165
- correct format with this argument.
166
-
167
- When ``filepath`` argument is file-like object, this argument is required.
168
-
169
- Valid values are ``"wav"``, ``"mp3"``, ``"ogg"``, ``"vorbis"``, ``"amr-nb"``,
170
- ``"amb"``, ``"flac"``, ``"sph"``, ``"gsm"``, and ``"htk"``.
171
-
172
- encoding (str or None, optional): Changes the encoding for the supported formats.
173
- This argument is effective only for supported formats, such as ``"wav"``, ``""amb"``
174
- and ``"sph"``. Valid values are;
175
-
176
- - ``"PCM_S"`` (signed integer Linear PCM)
177
- - ``"PCM_U"`` (unsigned integer Linear PCM)
178
- - ``"PCM_F"`` (floating point PCM)
179
- - ``"ULAW"`` (mu-law)
180
- - ``"ALAW"`` (a-law)
181
-
182
- Default values
183
- If not provided, the default value is picked based on ``format`` and ``bits_per_sample``.
184
-
185
- ``"wav"``, ``"amb"``
186
- - | If both ``encoding`` and ``bits_per_sample`` are not provided, the ``dtype`` of the
187
- | Tensor is used to determine the default value.
188
-
189
- - ``"PCM_U"`` if dtype is ``uint8``
190
- - ``"PCM_S"`` if dtype is ``int16`` or ``int32``
191
- - ``"PCM_F"`` if dtype is ``float32``
192
-
193
- - ``"PCM_U"`` if ``bits_per_sample=8``
194
- - ``"PCM_S"`` otherwise
195
-
196
- ``"sph"`` format;
197
- - the default value is ``"PCM_S"``
198
-
199
- bits_per_sample (int or None, optional): Changes the bit depth for the supported formats.
200
- When ``format`` is one of ``"wav"``, ``"flac"``, ``"sph"``, or ``"amb"``, you can change the
201
- bit depth. Valid values are ``8``, ``16``, ``32`` and ``64``.
202
-
203
- Default Value;
204
- If not provided, the default values are picked based on ``format`` and ``"encoding"``;
205
-
206
- ``"wav"``, ``"amb"``;
207
- - | If both ``encoding`` and ``bits_per_sample`` are not provided, the ``dtype`` of the
208
- | Tensor is used.
209
-
210
- - ``8`` if dtype is ``uint8``
211
- - ``16`` if dtype is ``int16``
212
- - ``32`` if dtype is ``int32`` or ``float32``
213
-
214
- - ``8`` if ``encoding`` is ``"PCM_U"``, ``"ULAW"`` or ``"ALAW"``
215
- - ``16`` if ``encoding`` is ``"PCM_S"``
216
- - ``32`` if ``encoding`` is ``"PCM_F"``
217
-
218
- ``"flac"`` format;
219
- - the default value is ``24``
220
-
221
- ``"sph"`` format;
222
- - ``16`` if ``encoding`` is ``"PCM_U"``, ``"PCM_S"``, ``"PCM_F"`` or not provided.
223
- - ``8`` if ``encoding`` is ``"ULAW"`` or ``"ALAW"``
224
-
225
- ``"amb"`` format;
226
- - ``8`` if ``encoding`` is ``"PCM_U"``, ``"ULAW"`` or ``"ALAW"``
227
- - ``16`` if ``encoding`` is ``"PCM_S"`` or not provided.
228
- - ``32`` if ``encoding`` is ``"PCM_F"``
229
-
230
- Supported formats/encodings/bit depth/compression are;
231
-
232
- ``"wav"``, ``"amb"``
233
- - 32-bit floating-point PCM
234
- - 32-bit signed integer PCM
235
- - 24-bit signed integer PCM
236
- - 16-bit signed integer PCM
237
- - 8-bit unsigned integer PCM
238
- - 8-bit mu-law
239
- - 8-bit a-law
240
-
241
- Note: Default encoding/bit depth is determined by the dtype of the input Tensor.
242
-
243
- ``"mp3"``
244
- Fixed bit rate (such as 128kHz) and variable bit rate compression.
245
- Default: VBR with high quality.
246
-
247
- ``"flac"``
248
- - 8-bit
249
- - 16-bit
250
- - 24-bit (default)
251
-
252
- ``"ogg"``, ``"vorbis"``
253
- - Different quality level. Default: approx. 112kbps
254
-
255
- ``"sph"``
256
- - 8-bit signed integer PCM
257
- - 16-bit signed integer PCM
258
- - 24-bit signed integer PCM
259
- - 32-bit signed integer PCM (default)
260
- - 8-bit mu-law
261
- - 8-bit a-law
262
- - 16-bit a-law
263
- - 24-bit a-law
264
- - 32-bit a-law
265
-
266
- ``"amr-nb"``
267
- Bitrate ranging from 4.75 kbit/s to 12.2 kbit/s. Default: 4.75 kbit/s
268
-
269
- ``"gsm"``
270
- Lossy Speech Compression, CPU intensive.
271
-
272
- ``"htk"``
273
- Uses a default single-channel 16-bit PCM format.
274
-
275
- Note:
276
- To save into formats that ``libsox`` does not handle natively, (such as ``"mp3"``,
277
- ``"flac"``, ``"ogg"`` and ``"vorbis"``), your installation of ``torchaudio`` has
278
- to be linked to ``libsox`` and corresponding codec libraries such as ``libmad``
279
- or ``libmp3lame`` etc.
280
- """
281
- if not torch.jit.is_scripting():
282
- if hasattr(filepath, "write"):
283
- raise RuntimeError("sox_io backend does not handle file-like object.")
284
- filepath = os.fspath(filepath)
285
- sox_ext.save_audio_file(
286
- filepath,
287
- src,
288
- sample_rate,
289
- channels_first,
290
- compression,
291
- format,
292
- encoding,
293
- bits_per_sample,
294
- )
@@ -1,13 +0,0 @@
1
- def __getattr__(name: str):
2
- if name == "AudioMetaData":
3
- import warnings
4
-
5
- warnings.warn(
6
- "`torchaudio.backend.common.AudioMetaData` has been moved to "
7
- "`torchaudio.AudioMetaData`. Please update the import path.",
8
- stacklevel=2,
9
- )
10
- from torchaudio import AudioMetaData
11
-
12
- return AudioMetaData
13
- raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
@@ -1,14 +0,0 @@
1
- def __getattr__(name: str):
2
- import warnings
3
-
4
- warnings.warn(
5
- "Torchaudio's I/O functions now support par-call bakcend dispatch. "
6
- "Importing backend implementation directly is no longer guaranteed to work. "
7
- "Please use `backend` keyword with load/save/info function, instead of "
8
- "calling the udnerlying implementation directly.",
9
- stacklevel=2,
10
- )
11
-
12
- from . import _no_backend
13
-
14
- return getattr(_no_backend, name)
@@ -1,14 +0,0 @@
1
- def __getattr__(name: str):
2
- import warnings
3
-
4
- warnings.warn(
5
- "Torchaudio's I/O functions now support par-call bakcend dispatch. "
6
- "Importing backend implementation directly is no longer guaranteed to work. "
7
- "Please use `backend` keyword with load/save/info function, instead of "
8
- "calling the udnerlying implementation directly.",
9
- stacklevel=2,
10
- )
11
-
12
- from torchaudio._backend import soundfile_backend
13
-
14
- return getattr(soundfile_backend, name)