-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path5_generate_spectrogram_3.py
More file actions
74 lines (65 loc) · 2.62 KB
/
5_generate_spectrogram_3.py
File metadata and controls
74 lines (65 loc) · 2.62 KB
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
import numpy as np
import pandas as pd
import os.path
import librosa
import IPython.display as ipd
from shutil import copyfile
import glob
import matplotlib.style as ms
import matplotlib.pyplot as plt
from tqdm import tqdm
import pickle
import random
import time
import IPython.display
import librosa.display
import joblib
from joblib import Parallel, delayed
from PIL import Image
import multiprocessing as mp
import pandas as pd
import math
labels_df = pd.read_csv('/home/mds-student/Documents/aDITYA/multimodal-speech-emotion-recognition-master/Preprocessing/df_iemocap/df_iemocap_1.csv')
iemocap_dir = '/home/mds-student/Documents/aDITYA/spec_augment-master/IEMOCAP_full_release_withoutVideos/Iemocap_sentences/'
save_dir = '/home/mds-student/Documents/aDITYA/multimodal-speech-emotion-recognition-master/Preprocessing/AudioVectors/'
audio_vectors_path= save_dir + 'audio_vectors_'
emotion_dict = {'ang': 0,
'hap': 1,
'exc': 2,
'sad': 3,
'fru': 4,
'fea': 5,
'sur': 6,
'neu': 7,
'xxx': 8,
'oth': 8,
'dis': 8}
emotion_full_dict = {'neu': 'neutral', 'ang': 'anger', 'hap': 'happiness', 'exc': 'excited', 'sad': 'sadness',
'fru':'frustrated', 'fea': 'fear', 'sur': 'surprised', 'xxx': 'others', 'oth': 'others', 'dis': 'others'}
pickle_to_subset = pd.read_csv('/home/mds-student/Documents/aDITYA/multimodal-speech-emotion-recognition-master/Preprocessing/pickle_to_subset/pickle_to_subset_1.csv')
pathAudio = iemocap_dir
pathImage = '/home/mds-student/Documents/aDITYA/spec_augment-master/IEMOCAP_full_release_withoutVideos/Iemocap_sentences/SpecAugment_spectrograms/'
#pickle_to_subset = pickle_to_subset[]
sample_rate = 44100
import time
import multiprocessing as mp
import ast
for row in tqdm(pickle_to_subset.itertuples(index=True, name='Pandas')):
a = getattr(row, "audio_vector")
image_fname = getattr(row, "filename")
label = getattr(row, "emotion")
res = ast.literal_eval(a)
res = np.asarray(res)
res = res.astype('float32')
S = librosa.feature.melspectrogram(y = res, sr = sample_rate, n_mels=256,hop_length=128,fmax=8000)
S_2 = librosa.power_to_db(S, ref=np.max)
plt.figure(figsize=(12,4))
librosa.display.specshow(S_2, sr=sample_rate, x_axis='time', y_axis='mel')
#plt.title('mel power spectrogram')
#plt.colorbar(format='%+02.0f dB')
#plt.tight_layout()
fig1 = plt.gcf()
plt.axis('off')
save_path = pathImage + emotion_full_dict[label] + '/' + image_fname + '.jpg'
fig1.savefig(save_path, dpi=50)
plt.close(fig1)