-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathda.py
More file actions
49 lines (40 loc) · 1.52 KB
/
da.py
File metadata and controls
49 lines (40 loc) · 1.52 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
import text2emotion as te
from ser import analyze_voice_emotion # Import SER
import os
# Map surreal words to emotional boosts
emotion_boost_map = {
"flying": "Surprise",
"air": "Surprise",
"car": "Surprise",
"mirror": "Fear",
"ghost": "Fear",
"dream": "Happy",
"silver": "Happy",
"dark": "Sad",
"lonely": "Sad",
}
surreal_words = [
"floating", "cloud", "ghost", "dream", "mirror", "inverted",
"silver", "giant", "upside-down", "portal", "spiral", "haunted", "shifting",
"flying", "car"
]
def analyze_emotions(text):
emotions = te.get_emotion(text)
# Boost emotion if surreal keywords are found
for word in text.lower().split():
word_clean = word.strip(".,!?")
if word_clean in emotion_boost_map:
key = emotion_boost_map[word_clean]
emotions[key] = min(1.0, emotions[key] + 0.2)
surreal_score = sum(1 for word in text.lower().split() if word.strip(".,!?") in surreal_words)
# 🔊 Voice emotion recognition (from dream_audio.wav)
if os.path.exists("dream_audio.wav"):
voice_emotion = analyze_voice_emotion("dream_audio.wav")
print(f"\n🎙️ Detected Voice Emotion: {voice_emotion}")
if voice_emotion in emotions:
emotions[voice_emotion] = min(1.0, emotions[voice_emotion] + 0.3)
print("\n🔍 Final Emotion Analysis:")
for emotion, score in emotions.items():
print(f"{emotion}: {score}")
print("\n🌀 Surrealism Score:", surreal_score)
return emotions, surreal_score