Skip to content

Update beginner_source/audio_preprocessing_tutorial.py #1199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions beginner_source/audio_preprocessing_tutorial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
torchaudio Tutorial
===================
Audio I/O and Pre-Processing with torchaudio
============================================

PyTorch is an open source deep learning platform that provides a
seamless path from research prototyping to production deployment with
Expand All @@ -10,7 +10,8 @@
preparation. ``torchaudio`` leverages PyTorch’s GPU support, and provides
many tools to make data loading easy and more readable. In this
tutorial, we will see how to load and preprocess data from a simple
dataset.
dataset. Please visit
`Audio I/O and Pre-Processing with torchaudio <https://pytorch.org/tutorials/beginner/audio_preprocessing_tutorial.html>`__ to learn more.

For this tutorial, please make sure the ``matplotlib`` package is
installed for easier visualization.
Expand All @@ -19,6 +20,7 @@

import torch
import torchaudio
import requests
import matplotlib.pyplot as plt

######################################################################
Expand All @@ -29,7 +31,13 @@
# call waveform the resulting raw audio signal.
#

filename = "../_static/img/steam-train-whistle-daniel_simon-converted-from-mp3.wav"
url = "https://pytorch.org/tutorials/_static/img/steam-train-whistle-daniel_simon-converted-from-mp3.wav"
r = requests.get(url)

with open('steam-train-whistle-daniel_simon-converted-from-mp3.wav', 'wb') as f:
f.write(r.content)

filename = "steam-train-whistle-daniel_simon-converted-from-mp3.wav"
waveform, sample_rate = torchaudio.load(filename)

print("Shape of waveform: {}".format(waveform.size()))
Expand Down Expand Up @@ -207,7 +215,7 @@ def normalize(tensor):
plt.plot(mu_law_encoding_waveform[0,:].numpy())

######################################################################
# You can see how the output fron ``torchaudio.functional.mu_law_encoding`` is the same as
# You can see how the output from ``torchaudio.functional.mu_law_encoding`` is the same as
# the output from ``torchaudio.transforms.MuLawEncoding``.
#
# Now let's experiment with a few of the other functionals and visualize their output. Taking our
Expand Down