Skip to content

Commit

Permalink
Merge pull request SeanNaren#496 from shamoons/495/soundfile
Browse files Browse the repository at this point in the history
Using soundfile.read to include more than just .wav files
  • Loading branch information
Sean Naren committed Jun 8, 2020
2 parents c21ed0d + b94488e commit 81cb575
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,4 @@ ENV/
models/
data/*.csv
data/*_dataset/
.vscode/
6 changes: 4 additions & 2 deletions data/data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import librosa
import numpy as np
import scipy.signal
import soundfile as sf
import sox
import torch
from scipy.io.wavfile import read
from torch.utils.data import Dataset, Sampler, DistributedSampler, DataLoader

from .spec_augment import spec_augment
Expand All @@ -21,7 +21,9 @@


def load_audio(path):
sample_rate, sound = read(path)
sound, sample_rate = sf.read(path, dtype='int16')
# TODO this should be 32768.0 to get twos-complement range.
# TODO the difference is negligible but should be fixed for new models.
sound = sound.astype('float32') / 32767 # normalize audio
if len(sound.shape) > 1:
if sound.shape[1] == 1:
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
scipy
numpy
soundfile
python-levenshtein
torch
torchelastic
Expand All @@ -9,3 +12,4 @@ matplotlib
flask
sox
sklearn
soundfile

0 comments on commit 81cb575

Please sign in to comment.