Views
No views yet
angry, calm, disgust, fearful, happy, neutral, sad, surprised (indices 0–7, alphabetical).| Metric | Value |
|---|---|
| Test accuracy (unseen speakers) | 46.1% |
| Best validation accuracy | 60.0% |
| Random baseline | 12.5% |
sr = 22050.n_mels = 128, then power_to_db(ref=np.max).130 frames → shape (128, 130).[0, 1] via (x + 80) / 80.(1, 1, 128, 130).1import numpy as np
2import librosa
3import onnxruntime as ort
4
5EMOTIONS = ["angry", "calm", "disgust", "fearful",
6 "happy", "neutral", "sad", "surprised"]
7
8session = ort.InferenceSession("emotion_cnn.onnx")
9
10
11def preprocess(path):
12 y, _ = librosa.load(path, sr=22050)
13 mel = librosa.power_to_db(librosa.feature.melspectrogram(y=y, sr=22050, n_mels=128), ref=np.max)
14 if mel.shape[1] > 130:
15 mel = mel[:, :130]
16 else:
17 mel = np.pad(mel, ((0, 0), (0, 130 - mel.shape[1])), mode="minimum")
18 mel = (mel + 80.0) / 80.0
19 return mel[None, None].astype(np.float32)
20
21
22logits = session.run(None, {session.get_inputs()[0].name: preprocess("clip.wav")})[0][0]
23probs = np.exp(logits) / np.exp(logits).sum()
24print(EMOTIONS[int(probs.argmax())], float(probs.max()))neutral class is unreliable.