|
1 | 1 | """
|
2 |
| -torchaudio Tutorial |
3 |
| -=================== |
| 2 | +Audio I/O and Pre-Processing with torchaudio |
| 3 | +============================================ |
4 | 4 |
|
5 | 5 | PyTorch is an open source deep learning platform that provides a
|
6 | 6 | seamless path from research prototyping to production deployment with
|
|
10 | 10 | preparation. ``torchaudio`` leverages PyTorch’s GPU support, and provides
|
11 | 11 | many tools to make data loading easy and more readable. In this
|
12 | 12 | tutorial, we will see how to load and preprocess data from a simple
|
13 |
| -dataset. |
| 13 | +dataset. Please visit |
| 14 | +`Audio I/O and Pre-Processing with torchaudio <https://pytorch.org/tutorials/beginner/audio_preprocessing_tutorial.html>`__ to learn more. |
14 | 15 |
|
15 | 16 | For this tutorial, please make sure the ``matplotlib`` package is
|
16 | 17 | installed for easier visualization.
|
17 | 18 |
|
18 | 19 | """
|
19 | 20 |
|
| 21 | +# Uncomment the following line to run in Google Colab |
| 22 | +# !pip install torchaudio |
20 | 23 | import torch
|
21 | 24 | import torchaudio
|
| 25 | +import requests |
22 | 26 | import matplotlib.pyplot as plt
|
23 | 27 |
|
24 | 28 | ######################################################################
|
|
29 | 33 | # call waveform the resulting raw audio signal.
|
30 | 34 | #
|
31 | 35 |
|
32 |
| -filename = "../_static/img/steam-train-whistle-daniel_simon-converted-from-mp3.wav" |
| 36 | +url = "https://pytorch.org/tutorials/_static/img/steam-train-whistle-daniel_simon-converted-from-mp3.wav" |
| 37 | +r = requests.get(url) |
| 38 | + |
| 39 | +with open('steam-train-whistle-daniel_simon-converted-from-mp3.wav', 'wb') as f: |
| 40 | + f.write(r.content) |
| 41 | + |
| 42 | +filename = "steam-train-whistle-daniel_simon-converted-from-mp3.wav" |
33 | 43 | waveform, sample_rate = torchaudio.load(filename)
|
34 | 44 |
|
35 | 45 | print("Shape of waveform: {}".format(waveform.size()))
|
@@ -207,7 +217,7 @@ def normalize(tensor):
|
207 | 217 | plt.plot(mu_law_encoding_waveform[0,:].numpy())
|
208 | 218 |
|
209 | 219 | ######################################################################
|
210 |
| -# You can see how the output fron ``torchaudio.functional.mu_law_encoding`` is the same as |
| 220 | +# You can see how the output from ``torchaudio.functional.mu_law_encoding`` is the same as |
211 | 221 | # the output from ``torchaudio.transforms.MuLawEncoding``.
|
212 | 222 | #
|
213 | 223 | # Now let's experiment with a few of the other functionals and visualize their output. Taking our
|
|
0 commit comments