Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

# json files
*.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import math
import librosa

DATASET_PATH = "path/to/marsyas/dataset"
DATASET_PATH = "path/to/gtzan/dataset" # can be downloaded from 'https://huggingface.co/datasets/marsyas/gtzan/resolve/main/data/genres.tar.gz'
JSON_PATH = "data_10.json"
SAMPLE_RATE = 22050
TRACK_DURATION = 30 # measured in seconds
Expand Down Expand Up @@ -48,7 +48,10 @@ def save_mfcc(dataset_path, json_path, num_mfcc=13, n_fft=2048, hop_length=512,

# load audio file
file_path = os.path.join(dirpath, f)
signal, sample_rate = librosa.load(file_path, sr=SAMPLE_RATE)
try:
signal, sample_rate = librosa.load(file_path, sr=SAMPLE_RATE)
except Exception:
continue

# process all segments of audio file
for d in range(num_segments):
Expand All @@ -58,7 +61,7 @@ def save_mfcc(dataset_path, json_path, num_mfcc=13, n_fft=2048, hop_length=512,
finish = start + samples_per_segment

# extract mfcc
mfcc = librosa.feature.mfcc(signal[start:finish], sample_rate, n_mfcc=num_mfcc, n_fft=n_fft, hop_length=hop_length)
mfcc = librosa.feature.mfcc(y=signal[start:finish], sr=sample_rate, n_mfcc=num_mfcc, n_fft=n_fft, hop_length=hop_length)
mfcc = mfcc.T

# store only mfcc feature with expected number of vectors
Expand Down