README.md 1.22 KB
Newer Older
Soumith Chintala's avatar
Soumith Chintala committed
1
Load Audio files directly into PyTorch Tensors
Soumith Chintala's avatar
Soumith Chintala committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
================================================

Audio library for PyTorch
 * Support audio I/O (Load files)

Load the following formats into a torch Tensor
 * mp3, wav, aac, ogg, flac, avr, cdda, cvs/vms,
 * aiff, au, amr, mp2, mp4, ac3, avi, wmv,
 * mpeg, ircam and any other format supported by libsox.

Dependencies
------------
* libsox v14.3.2 or above

Quick install on
OSX (Homebrew):
```bash
brew install sox
```
Linux (Ubuntu):
```bash
sudo apt-get install sox libsox-dev libsox-fmt-all
```

Installation
------------

```bash
Adam Paszke's avatar
Adam Paszke committed
30
pip install cffi
Soumith Chintala's avatar
Soumith Chintala committed
31
32
33
34
35
36
37
38
39
python setup.py install
```

Quick Usage
-----------

```python
import torchaudio
sound, sample_rate = torchaudio.load('foo.mp3')
SeanNaren's avatar
SeanNaren committed
40
torchaudio.save('foo_save.mp3', sound, sample_rate) # saves tensor to file
Soumith Chintala's avatar
Soumith Chintala committed
41
42
43
44
45
46
47
48
49
50
51
52
53
```

API Reference
-----------
torchaudio.load
```
loads an audio file into a Tensor
audio.load(
	string,  # path to file
	out=None, # optionally pass output Tensor (any CPU Tensor type)
)
```

SeanNaren's avatar
SeanNaren committed
54
55
56
57
torchaudio.save
```
saves a tensor into an audio file. The extension of the given path is used as the saving format.
audio.save(
SeanNaren's avatar
SeanNaren committed
58
	string, # path to file
SeanNaren's avatar
SeanNaren committed
59
60
61
62
63
	tensor, # NSamples x NChannels 2D tensor
	number, # sample_rate of the audio to be saved as
)
```