forked from MiteshPuthran/Speech-Emotion-Analyzer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
inference.py
54 lines (54 loc) · 1.56 KB
/
inference.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
##Inference Script
#importing modules
from keras.models import model_from_json
import keras
import librosa
import numpy as np
from tensorflow.keras import optimizers
import os
import pandas as pd
import librosa
import glob
json_file = open('model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
# load weights into new model
loaded_model.load_weights("saved_models/Emotion_Voice_Detection_Model.h5")
print("Loaded model from disk")
data, sampling_rate = librosa.load('output10.wav')
X, sample_rate = librosa.load('Input4.m4a', res_type='kaiser_fast',duration=2.5,sr=22050*2,offset=0.5)
sample_rate = np.array(sample_rate)
mfccs = np.mean(librosa.feature.mfcc(y=X, sr=sample_rate, n_mfcc=13),axis=0)
featurelive = mfccs
livedf2 = featurelive
#import pandas as pd
livedf2= pd.DataFrame(data=livedf2)
livedf2 = livedf2.stack().to_frame().T
twodim= np.expand_dims(livedf2, axis=2)
livepreds = loaded_model.predict(twodim,
batch_size=32,
verbose=1)
livepreds1=livepreds.argmax(axis=1)
liveabc = livepreds1.astype(int).flatten()
#Labels assigned as per README of main repo.
if liveabc == 0:
print("Female_angry")
elif liveabc == 1:
print("Female Calm")
elif liveabc == 2:
print("Female Fearful")
elif liveabc == 3:
print("Female Happy")
elif liveabc == 4:
print("Female Sad")
elif liveabc == 5:
print("Male Angry")
elif liveabc == 6:
print("Male calm")
elif liveabc == 7:
print("Male Fearful")
elif liveabc == 8:
print("Male Happy")
elif liveabc == 9:
print("Male sad")