Commit e1fe89d1 authored by Quentin Aristote's avatar Quentin Aristote
Browse files

corrected code

parent 31a33a22
......@@ -185,7 +185,7 @@ def getSounds(directory = '.',
filename = title + '.mp3'
path = os.path.join(directory, filename)
print('Downloading {filename} ...'.format(filename = filename))
if not(os.path.isfile(path)) or overwrite or not(title in to_ignore) :
if (not(os.path.isfile(path)) or overwrite) and not(title in to_ignore) :
sound_html = getSoundHTML(title)
try :
_ = downloadSound(sound_html, path = path)
......
......@@ -19,8 +19,7 @@ def soundToSpectrogram(path, sample_rate = 16000, duration = 30) :
waveform, orig_freq = torchaudio.load(path)
# Convert to mono
waveform_mono = waveform.mean(dim = 0)
waveform = torch.stack([waveform_mono.detach(), waveform_mono.detach()])
waveform = waveform.mean(dim = 0, keepdim = True)
# Resample
resample = transforms.Resample(orig_freq = orig_freq, new_freq = sample_rate)
......@@ -30,7 +29,7 @@ def soundToSpectrogram(path, sample_rate = 16000, duration = 30) :
nb_frames = duration * sample_rate
waveform = waveform[:, :nb_frames]
nb_frames_missing = nb_frames - waveform.size()[1]
waveform = torch.cat([waveform, torch.zeros((2, nb_frames_missing))], dim = 1)
waveform = torch.cat([waveform, torch.zeros((1, nb_frames_missing))], dim = 1)
# Compute the Mel-spectrogram
melspectrogram = transforms.MelSpectrogram(sample_rate = sample_rate)
......@@ -60,7 +59,7 @@ def getSpectrograms(dir_source, dir_target,
path_target = os.path.join(dir_target, title + '.pt')
print('Computing the Mel-spectrogram of {filename} ...'.format(filename = filename))
if overwrite or not(os.path.isfile(path_target)) :
if (overwrite or not(os.path.isfile(path_target))) and not(title in to_ignore) :
try :
spectrogram = soundToSpectrogram(path_source, sample_rate = sample_rate, duration = duration)
torch.save(spectrogram, path_target)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment