-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathaux_test_spectro.py
60 lines (51 loc) · 2.08 KB
/
aux_test_spectro.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import librosa
import librosa.display
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
from matplotlib.pyplot import specgrame
def load_sound_files(file_paths):
raw_sounds = []
for fp in file_paths:
X,sr = librosa.load(fp)
raw_sounds.append(X)
return raw_sounds
def plot_waves(sound_names,raw_sounds):
i = 1
fig = plt.figure(figsize=(50,60), dpi = 900)
for n,f in zip(sound_names,raw_sounds):
plt.subplot(10,1,i)
librosa.display.waveplot(np.array(f),sr=2108)
plt.title(n.title())
i += 1
plt.suptitle("Figure 1: Waveplot",x=0.5, y=0.915,fontsize=18)
plt.show()
def plot_specgram(sound_names,raw_sounds):
i = 1
fig = plt.figure(figsize=(25,60), dpi = 900)
for n,f in zip(sound_names,raw_sounds):
plt.subplot(10,1,i)
specgram(np.array(f), Fs=22050)
plt.title(n.title())
i += 1
plt.suptitle("Figure 2: Spectrogram",x=0.5, y=0.915,fontsize=18)
plt.show()
def plot_log_power_specgram(sound_names,raw_sounds):
i = 1
fig = plt.figure(figsize=(25,60), dpi = 900)
for n,f in zip(sound_names,raw_sounds):
plt.subplot(10,1,i)
D = librosa.logamplitude(np.abs(librosa.stft(f))**2, ref_power=np.max)
librosa.display.specshow(D,x_axis='time' ,y_axis='log')
plt.title(n.title())
i += 1
plt.suptitle("Figure 3: Log power spectrogram",x=0.5, y=0.915,fontsize=18)
plt.show()
sound_file_paths = ['<file_path_of_music_file>/magnatagatune/00000000000000000100000100100000000000000001000001_1160.wav',
'<file_path_of_music_file>/magnatagatune/00000000000000010000000000000000000000001000000000_25692.wav',
'<file_path_of_music_file>/magnatagatune/00010000000001000000000000000000000000000000001000_21648.wav']
sound_names = ['india','flute','techno']
raw_sounds = load_sound_files(sound_file_paths)
plot_waves(sound_names,raw_sounds)
plot_specgram(sound_names,raw_sounds)
plot_log_power_specgram(sound_names,raw_sounds)