Created
November 26, 2018 09:59
-
-
Save SuperShinyEyes/d507022b29d5be14a404b529737ec4f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import soundfile as sf | |
import librosa | |
import librosa.display | |
plt.rcParams['font.family'] = 'serif' | |
plt.rcParams['font.serif'] = 'Ubuntu' | |
plt.rcParams['font.monospace'] = 'Ubuntu Mono' | |
plt.rcParams['font.size'] = 10 | |
plt.rcParams['axes.labelsize'] = 10 # Time and Hz, i.e. labels | |
plt.rcParams['axes.labelweight'] = 'bold' | |
plt.rcParams['xtick.labelsize'] = 15 # Time(x) tick values | |
plt.rcParams['ytick.labelsize'] = 15 # Hz(y) tick values | |
plt.rcParams['legend.fontsize'] = 17 | |
plt.rcParams['figure.titlesize'] = 10 | |
plt.rcParams['axes.titlesize'] = 14 # Title font | |
y, sr = librosa.load(librosa.util.example_audio_file()) | |
plt.figure(figsize=(17, 9)) | |
#---------------------------------------------------- | |
# Reference | |
plt.subplot(3, 1, 1, facecolor='w') | |
y, sr = sf.read("adele/test/11 Someone Like You.wav", 44100*15, ) | |
X = librosa.stft(y[:44100*15, 0]) | |
Xdb = librosa.amplitude_to_db(X) | |
librosa.display.specshow(Xdb, sr=44100, y_axis='hz') | |
plt.colorbar(format='%+2.0f dB') | |
plt.title('Reference 44.1 kHz') | |
#---------------------------------------------------- | |
# Damaged | |
plt.subplot(3, 1, 2) | |
y, sr = librosa.core.load("adele/test/4410/11 Someone Like You.wav", sr=None) | |
X = librosa.stft(y[:4410*15]) | |
Xdb = librosa.amplitude_to_db(X) | |
librosa.display.specshow(Xdb, sr=4410, y_axis='hz') | |
plt.colorbar(format='%+2.0f dB') | |
plt.title('Dowmsample 4410Hz') | |
#---------------------------------------------------- | |
# Decoded | |
plt.subplot(3, 1, 3) | |
y, sr = librosa.core.load("adele/test/decoded/11 Someone Like You.mp3", sr=None) | |
X = librosa.stft(y) | |
Xdb = librosa.amplitude_to_db(X) | |
librosa.display.specshow(Xdb, sr=44100, x_axis='time', y_axis='hz') | |
plt.colorbar(format='%+2.0f dB') | |
plt.title('Decoded 44.1 kHz') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment