Update main.py
Browse files
main.py
CHANGED
@@ -6,6 +6,7 @@ import numpy as np
|
|
6 |
import joblib
|
7 |
import os
|
8 |
import sys
|
|
|
9 |
|
10 |
# librosa is a Python library for analyzing audio and music. It can be used to extract the data from the audio files we will see it later.
|
11 |
import librosa
|
@@ -44,32 +45,47 @@ warnings.filterwarnings("ignore", category=DeprecationWarning)
|
|
44 |
model=from_pretrained_keras( 'Mohamed41/MODEL_EMOTION_AR_TEXT_72P')
|
45 |
|
46 |
|
47 |
-
def feat_ext(data):
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
# ZCR Persody features or Low level ascoustic features
|
50 |
result = np.array([])
|
51 |
zcr = np.mean(librosa.feature.zero_crossing_rate(y=data).T, axis=0)
|
52 |
-
result
|
53 |
-
#
|
54 |
-
#
|
55 |
-
#
|
56 |
-
mfcc = np.mean(librosa.feature.mfcc(y=data, sr=22050,
|
57 |
-
result = np.hstack((result, mfcc))
|
58 |
return result
|
59 |
|
60 |
-
|
61 |
-
scaler = joblib.load('scaler.joblib')
|
62 |
-
encoder = joblib.load('encoder.joblib')
|
63 |
-
|
64 |
-
|
65 |
def get_predict_feat(path):
|
66 |
-
d, s_rate
|
67 |
-
res
|
68 |
-
result
|
69 |
-
result
|
70 |
-
i_result =
|
71 |
-
final_result
|
72 |
-
|
73 |
return final_result
|
74 |
|
75 |
|
@@ -93,5 +109,5 @@ async def read_root( file: UploadFile = File(...)):
|
|
93 |
# json_data = await request.json()
|
94 |
# except error:
|
95 |
# print (error)
|
96 |
-
|
97 |
-
return {"filename": file.filename, "filepath": f"/app/{file.filename}"}
|
|
|
6 |
import joblib
|
7 |
import os
|
8 |
import sys
|
9 |
+
import pikle
|
10 |
|
11 |
# librosa is a Python library for analyzing audio and music. It can be used to extract the data from the audio files we will see it later.
|
12 |
import librosa
|
|
|
45 |
model=from_pretrained_keras( 'Mohamed41/MODEL_EMOTION_AR_TEXT_72P')
|
46 |
|
47 |
|
48 |
+
# def feat_ext(data):
|
49 |
+
# # Time_domain_features
|
50 |
+
# # ZCR Persody features or Low level ascoustic features
|
51 |
+
# result = np.array([])
|
52 |
+
# zcr = np.mean(librosa.feature.zero_crossing_rate(y=data).T, axis=0)
|
53 |
+
# result = np.hstack((result, zcr)) # stacking horizontally
|
54 |
+
# # Frequency_domain_features
|
55 |
+
# # Spectral and wavelet Features
|
56 |
+
# # MFCC
|
57 |
+
# mfcc = np.mean(librosa.feature.mfcc(y=data, sr=22050, n_mfcc=40).T, axis=0)
|
58 |
+
# result = np.hstack((result, mfcc)) # stacking horizontally
|
59 |
+
# return result
|
60 |
+
|
61 |
+
|
62 |
+
with open('scaler2.pickle', 'rb') as f:
|
63 |
+
scaler = pickle.load(f)
|
64 |
+
|
65 |
+
with open('encoder2.pickle', 'rb') as f:
|
66 |
+
encoder = pickle.load(f)
|
67 |
+
|
68 |
+
def feat_ext_test(data):
|
69 |
+
#Time_domain_features
|
70 |
# ZCR Persody features or Low level ascoustic features
|
71 |
result = np.array([])
|
72 |
zcr = np.mean(librosa.feature.zero_crossing_rate(y=data).T, axis=0)
|
73 |
+
result=np.hstack((result, zcr)) # stacking horizontally
|
74 |
+
#Frequency_domain_features
|
75 |
+
#Spectral and wavelet Features
|
76 |
+
#MFCC
|
77 |
+
mfcc = np.mean(librosa.feature.mfcc(y=data, sr=22050,n_mfcc=40).T, axis=0)
|
78 |
+
result = np.hstack((result, mfcc)) # stacking horizontally
|
79 |
return result
|
80 |
|
|
|
|
|
|
|
|
|
|
|
81 |
def get_predict_feat(path):
|
82 |
+
d, s_rate= librosa.load(path, duration=2.5, offset=0.6)
|
83 |
+
res=feat_ext_test(d)
|
84 |
+
result=np.array(res)
|
85 |
+
result=np.reshape(result,newshape=(1,41))
|
86 |
+
i_result = scaler2.transform(result)
|
87 |
+
final_result=np.expand_dims(i_result, axis=2)
|
88 |
+
|
89 |
return final_result
|
90 |
|
91 |
|
|
|
109 |
# json_data = await request.json()
|
110 |
# except error:
|
111 |
# print (error)
|
112 |
+
x = prediction("/app/{file.filename}")
|
113 |
+
return {"filename": file.filename, "filepath": f"/app/{file.filename}","prediction()":x}
|