Skip to content

Commit 79e9642

Browse files
Remove librosa dependency from feature augmentation tutorial (#4004)
Co-authored-by: Sam Anklesaria <[email protected]>
1 parent 6ad76d1 commit 79e9642

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

examples/tutorials/audio_feature_augmentation_tutorial.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77
88
"""
99

10-
# When running this tutorial in Google Colab, install the required packages
11-
# with the following.
12-
# !pip install torchaudio librosa
13-
1410
import torch
1511
import torchaudio
1612
import torchaudio.transforms as T
13+
import numpy as np
1714

1815
print(torch.__version__)
1916
print(torchaudio.__version__)
@@ -23,7 +20,6 @@
2320
# -----------
2421
#
2522

26-
import librosa
2723
import matplotlib.pyplot as plt
2824
from IPython.display import Audio
2925
from torchaudio.utils import download_asset
@@ -98,10 +94,16 @@ def get_spectrogram(
9894
######################################################################
9995
# Visualization
10096
# ~~~~~~~~~~~~~
97+
98+
def power_to_db(S):
99+
S = np.asarray(S)
100+
return 10.0 * np.log10(np.maximum(1e-10, S))
101+
102+
101103
def plot():
102104
def plot_spec(ax, spec, title):
103105
ax.set_title(title)
104-
ax.imshow(librosa.amplitude_to_db(spec), origin="lower", aspect="auto")
106+
ax.imshow(power_to_db(spec**2), origin="lower", aspect="auto")
105107

106108
fig, axes = plt.subplots(3, 1, sharex=True, sharey=True)
107109
plot_spec(axes[0], torch.abs(spec_12[0]), title="Stretched x1.2")
@@ -157,7 +159,7 @@ def preview(spec, rate=16000):
157159
def plot():
158160
def plot_spec(ax, spec, title):
159161
ax.set_title(title)
160-
ax.imshow(librosa.power_to_db(spec), origin="lower", aspect="auto")
162+
ax.imshow(power_to_db(spec), origin="lower", aspect="auto")
161163

162164
fig, axes = plt.subplots(3, 1, sharex=True, sharey=True)
163165
plot_spec(axes[0], spec[0], title="Original")

0 commit comments

Comments
 (0)