forked from x4nth055/emotion-recognition-using-speech
-
Notifications
You must be signed in to change notification settings - Fork 1
/
predict.py
28 lines (23 loc) · 885 Bytes
/
predict.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
import json
import os
import tempfile
from pathlib import Path
import cog
from emotion_recognition import EmotionRecognizer
class EmoPredictor(cog.Predictor):
def setup(self):
"""Load the emotion recognition model and (quickly) train it"""
# self.rec = EmotionRecognizer(None, emotions=["boredom", "neutral"], features=["mfcc"])
self.rec = EmotionRecognizer(
None,
emotions=["sad", "neutral", "happy"],
features=["mfcc"],
probability=True,
)
# evaluate all models in `grid` folder and determine the best one in terms of test accuracy
self.rec.determine_best_model()
@cog.input("input", type=Path, help="Speech audio file")
def predict(self, input):
"""Compute emotion prediction"""
prediction = self.rec.predict_proba(str(input))
return prediction