import numpy, scipy, matplotlib.pyplot as plt, sklearn, stanford_mir, IPython.display
%matplotlib inline
Load a file:
x, fs = librosa.load('1_bar_funk_groove.mp3')
Compute the STFT:
X = librosa.stft(x)
Take the log-ampllitude for display purposes:
Xmag = librosa.logamplitude(X)
Display the log-magnitude spectrogram:
librosa.display.specshow(Xmag, sr=fs, x_axis='time', y_axis='log')
Perform harmonic-percussive source separation:
H, P = librosa.decompose.hpss(X)
Compute the log-amplitudes of the outputs:
Hmag = librosa.logamplitude(H)
Pmag = librosa.logamplitude(P)
Display each output:
librosa.display.specshow(Hmag, sr=fs, x_axis='time', y_axis='log')
librosa.display.specshow(Pmag, sr=fs, x_axis='time', y_axis='log')
Transform the harmonic output back to the time domain:
h = librosa.istft(H)
Listen to the harmonic output:
IPython.display.Audio(h, rate=fs)
Transform the percussive output back to the time domain:
p = librosa.istft(P)
Listen to the percussive output:
IPython.display.Audio(p, rate=fs)