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

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

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

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

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
18
19
20
21
   Instead of calling functions in ``torchaudio.backend`` directly, please use ``torchaudio.info``, ``torchaudio.load``, ``torchaudio.load_wav`` and ``torchaudio.save`` with proper backend set with :func:`torchaudio.set_audio_backend`.

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
.. autofunction:: torchaudio.backend.sox_io_backend.load_wav
62
63
64
65
66


save
----

67
.. autofunction:: torchaudio.backend.sox_io_backend.save
68

69
.. _soundfile_backend:
70
71
72
73

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

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

76
You can switch from another backend to the ``"soundfile"`` backend with the following;
77
78
79

.. code::

80
   torchaudio.set_audio_backend("soundfile")
81
82

info
83
----
84

85
.. autofunction:: torchaudio.backend.soundfile_backend.info
86
87

load
Prabhat Roy's avatar
Prabhat Roy committed
88
----
89

90
.. autofunction:: torchaudio.backend.soundfile_backend.load
91

92
.. autofunction:: torchaudio.backend.soundfile_backend.load_wav
93
94
95


save
Prabhat Roy's avatar
Prabhat Roy committed
96
----
97

98
.. autofunction:: torchaudio.backend.soundfile_backend.save