Skip to content

Commit

Permalink
beginner_source/audio_datasets_tutorial.rst (#947)
Browse files Browse the repository at this point in the history
* beginner_source/audio_datasets_tutorial.rst ๋ฒˆ์—ญ ์ถ”๊ฐ€
  • Loading branch information
aromadsh authored Oct 14, 2024
1 parent cc57c23 commit 3831f01
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions beginner_source/audio_datasets_tutorial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""
์˜ค๋””์˜ค ๋ฐ์ดํ„ฐ์…‹
==============
**์ €์ž**: `Moto Hira <[email protected]>`__
**๋ฒˆ์—ญ**: `๋ฐฑ์Šน์—ฝ <https://github.com/aromadsh>`__
``torchaudio``๋Š” ๊ณต์šฉ์œผ๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ์ผ๋ฐ˜์ ์ธ ๋ฐ์ดํ„ฐ์…‹์— ์‰ฝ๊ฒŒ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐ์ดํ„ฐ์…‹ ๋ชฉ๋ก์€ ๊ณต์‹ ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”.
"""

import torch
import torchaudio

print(torch.__version__)
print(torchaudio.__version__)

######################################################################

import os

import IPython

import matplotlib.pyplot as plt


_SAMPLE_DIR = "_assets"
YESNO_DATASET_PATH = os.path.join(_SAMPLE_DIR, "yes_no")
os.makedirs(YESNO_DATASET_PATH, exist_ok=True)


def plot_specgram(waveform, sample_rate, title="Spectrogram"):
waveform = waveform.numpy()

figure, ax = plt.subplots()
ax.specgram(waveform[0], Fs=sample_rate)
figure.suptitle(title)
figure.tight_layout()


######################################################################
#
# ์—ฌ๊ธฐ์„œ :py:class:`torchaudio.datasets.YESNO` ๋ฐ์ดํ„ฐ์…‹์˜ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
#

dataset = torchaudio.datasets.YESNO(YESNO_DATASET_PATH, download=True)

######################################################################
#
i = 1
waveform, sample_rate, label = dataset[i]
plot_specgram(waveform, sample_rate, title=f"Sample {i}: {label}")
IPython.display.Audio(waveform, rate=sample_rate)

######################################################################
#
i = 3
waveform, sample_rate, label = dataset[i]
plot_specgram(waveform, sample_rate, title=f"Sample {i}: {label}")
IPython.display.Audio(waveform, rate=sample_rate)

######################################################################
#
i = 5
waveform, sample_rate, label = dataset[i]
plot_specgram(waveform, sample_rate, title=f"Sample {i}: {label}")
IPython.display.Audio(waveform, rate=sample_rate)

i = 5
waveform, sample_rate, label = dataset[i]
plot_specgram(waveform, sample_rate, title=f"Sample {i}: {label}")
IPython.display.Audio(waveform, rate=sample_rate)

0 comments on commit 3831f01

Please sign in to comment.