backend.rst 2.29 KB
Newer Older
1
2
3
4
5
.. _backend:

torchaudio.backend
==================

6
7
Overview
~~~~~~~~
8

9
:mod:`torchaudio.backend` module provides implementations for audio file I/O functionalities, which are ``torchaudio.info``, ``torchaudio.load``, and ``torchaudio.save``.
10
11
12

There are currently four implementations available.

13
14
* :ref:`"sox_io" <sox_io_backend>` (default on Linux/macOS)
* :ref:`"soundfile" <soundfile_backend>` (default on Windows)
15
16

.. note::
17
   Instead of calling functions in ``torchaudio.backend`` directly, please use ``torchaudio.info``, ``torchaudio.load``, and ``torchaudio.save`` with proper backend set with :func:`torchaudio.set_audio_backend`.
18
19
20
21

Availability
------------

Prabhat Roy's avatar
Prabhat Roy committed
22
``"sox_io"`` backend requires C++ extension module, which is included in Linux/macOS binary distributions. This backend is not available on Windows.
23

24
``"soundfile"`` backend requires ``SoundFile``. Please refer to `the SoundFile documentation <https://pysoundfile.readthedocs.io/en/latest/>`_ for the installation.
25
26
27
28

Common Data Structure
~~~~~~~~~~~~~~~~~~~~~

29
30
31
32
33
34
35
Structures used to report the metadata of audio files.

AudioMetaData
-------------

.. autoclass:: torchaudio.backend.common.AudioMetaData

36
.. _sox_io_backend:
37

38
39
Sox IO Backend
~~~~~~~~~~~~~~
40

41
The ``sox_io`` backend is available and default on Linux/macOS and not available on Windows.
42

43
44
45
I/O functions of this backend support `TorchScript <https://pytorch.org/docs/stable/jit.html>`_.

You can switch from another backend to the ``sox_io`` backend with the following;
46
47
48

.. code::

49
   torchaudio.set_audio_backend("sox_io")
50
51
52
53

info
----

54
.. autofunction:: torchaudio.backend.sox_io_backend.info
55
56
57
58

load
----

59
.. autofunction:: torchaudio.backend.sox_io_backend.load
60
61
62
63

save
----

64
.. autofunction:: torchaudio.backend.sox_io_backend.save
65

66
.. _soundfile_backend:
67
68
69
70

Soundfile Backend
~~~~~~~~~~~~~~~~~

71
72
The ``"soundfile"`` backend is available when `SoundFile <https://pysoundfile.readthedocs.io/en/latest/>`_ is installed. This backend is the default on Windows.

73
You can switch from another backend to the ``"soundfile"`` backend with the following;
74
75
76

.. code::

77
   torchaudio.set_audio_backend("soundfile")
78
79

info
80
----
81

82
.. autofunction:: torchaudio.backend.soundfile_backend.info
83
84

load
Prabhat Roy's avatar
Prabhat Roy committed
85
----
86

87
.. autofunction:: torchaudio.backend.soundfile_backend.load
88
89

save
Prabhat Roy's avatar
Prabhat Roy committed
90
----
91

92
.. autofunction:: torchaudio.backend.soundfile_backend.save