-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo_spec.py
75 lines (65 loc) · 2.18 KB
/
demo_spec.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from utils.plotting import plot_spectrogram
import librosa
from utils.audio import Audio
from utils.hparams import HParam
import argparse
import numpy as np
parser = argparse.ArgumentParser()
parser.add_argument('-b', '--base_dir', type=str, default='.',
help="Root directory of run.")
parser.add_argument('-c', '--config', type=str, required=True, default='config/config.yaml',
help="yaml file for configuration")
args = parser.parse_args()
hp = HParam(args.config)
# hp.audio.win_length = hp.audio.win_length * 3
# hp.audio.hop_length = hp.audio.hop_length * 3
myaudio = Audio(hp)
sk1_1, _ = librosa.load('utils/sp1_1.wav', 16000)
sk1_2, _ = librosa.load('utils/sp1_2.wav', 16000)
sk2_1, _ = librosa.load('utils/sp2_1.wav', 16000)
sk2_2, _ = librosa.load('utils/sp2_2.wav', 16000)
# ssk1_1, _ = myaudio.wav2spec(sk1_1)
# ssk1_1 = ssk1_1[:102, :125]
# print(ssk1_1.shape)
# plot_spectrogram(ssk1_1, 'sk1_1')
#
# ssk1_2, _ = myaudio.wav2spec(sk1_2)
# ssk1_2 = ssk1_2[:102, :125]
# plot_spectrogram(ssk1_2, 'sk1_2')
#
# ssk2_1, _ = myaudio.wav2spec(sk2_1)
# ssk2_1 = ssk2_1[:102, :125]
# plot_spectrogram(ssk2_1, 'sk2_1')
#
# ssk2_2, _ = myaudio.wav2spec(sk2_2)
# ssk2_2 = ssk2_2[:102, :125]
# plot_spectrogram(ssk2_2, 'sk2_2')
#############################################3
ssk1_1, _ = myaudio.wav2spec(sk1_1)
ssk1_1 = ssk1_1[:300, :125]
print(ssk1_1.shape)
plot_spectrogram(ssk1_1, 'sk1_1')
ssk1_2, _ = myaudio.wav2spec(sk1_2)
ssk1_2 = ssk1_2[50:350, :125]
plot_spectrogram(ssk1_2, 'sk1_2')
ssk2_1, _ = myaudio.wav2spec(sk2_1)
ssk2_1 = ssk2_1[:300, :125]
plot_spectrogram(ssk2_1, 'sk2_1')
ssk2_2, _ = myaudio.wav2spec(sk2_2)
ssk2_2 = ssk2_2[:300, :125]
plot_spectrogram(ssk2_2, 'sk2_2')
# ssk1_1 = ssk1_1.reshape(6, -1, 125)
# vec_ssk1_1 = np.mean(ssk1_1, axis=1)
# plot_spectrogram(vec_ssk1_1, 'vec_sk1_1')
#
# ssk1_2 = ssk1_2.reshape(6, -1, 125)
# vec_ssk1_2 = np.mean(ssk1_2, axis=1)
# plot_spectrogram(vec_ssk1_2, 'vec_sk1_2')
#
# ssk2_1 = ssk2_1.reshape(6, -1, 125)
# vec_ssk2_1 = np.mean(ssk2_1, axis=1)
# plot_spectrogram(vec_ssk2_1, 'vec_sk2_1')
#
# ssk2_2 = ssk2_2.reshape(6, -1, 125)
# vec_ssk2_2 = np.mean(ssk2_2, axis=1)
# plot_spectrogram(vec_ssk2_2, 'vec_sk2_2')