Beispiel #1
0
def process_directory(dir, n_rate):
    signal = []

    for j, audioname in enumerate(f[dir]):
        holder_signal, sr = Audio.read(f'{origin_path}/{dir}/{audioname}',
                                       sr=n_rate)

        signal.extend(Audio.trim(holder_signal, 20))

    signal = array(signal)

    Audio.write(f'{dest_path}/{n_rate}/{dir}.wav', signal, n_rate)
warped_masked_spectrogram = spec_augment_tensorflow.spec_augment(mfcc)
warped_masked_spectrogram = warped_masked_spectrogram.numpy()

# %%
plt.figure(figsize=(10, 4))
librosa.display.specshow(librosa.power_to_db(warped_masked_spectrogram[0, :, :,
                                                                       0],
                                             ref=np.max),
                         y_axis='mel',
                         fmax=8000,
                         x_axis='time')
plt.tight_layout()
plt.title('SpecAugmented')
plt.show()
plt.close()
audio_signal = librosa.core.spectrum.griffinlim(
    warped_masked_spectrogram[0, :, :, 0])
Audio.write('test/warped_audio.wav', audio_signal, sr)
# %%
plt.figure(figsize=(10, 4))
librosa.display.specshow(librosa.power_to_db(mfcc[0, :, :, 0], ref=np.max),
                         y_axis='mel',
                         fmax=8000,
                         x_axis='time')
plt.tight_layout()
plt.title('MFCC')
plt.show()
plt.close()
audio_signal = librosa.core.spectrum.griffinlim(mfcc[0, :, :, 0])
Audio.write('test/mfcc_audio.wav', audio_signal, sr)