-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpression
95 lines (86 loc) · 2.29 KB
/
expression
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import numpy as np
import pygame
# 1. Emotion Coordinates
EMOTION_GROUPS = {
'group1': ['spiritual', 'solemn', 'serious'],
'group2': ['sad', 'dark', 'frustrated'],
'group3': ['sentimental', 'tender', 'dreamy'],
'group4': ['quiet', 'satisfying', 'soothing'],
'group5': ['humorous', 'fanciful', 'graceful'],
'group6': ['happy', 'bright', 'cheerful'],
'group7': ['exciting', 'dramatic', 'passionate'],
'group8': ['vigorous', 'robust', 'majestic']
}
# 2. Detailed Frequencies and Amplitudes for each emotion
FREQUENCIES = {
'spiritual': 260.00,
'solemn': 262.00,
'serious': 264.00,
'sad': 291.00,
'dark': 293.50,
'frustrated': 296.00,
'sentimental': 328.00,
'tender': 330.50,
'dreamy': 333.00,
'quiet': 348.00,
'satisfying': 350.50,
'soothing': 353.00,
'humorous': 390.00,
'fanciful': 392.50,
'graceful': 395.00,
'happy': 438.00,
'bright': 441.50,
'cheerful': 444.00,
'exciting': 492.00,
'dramatic': 495.50,
'passionate': 498.00,
'vigorous': 522.00,
'robust': 524.50,
'majestic': 527.00
}
AMPLITUDES = {
'spiritual': 0.19,
'solemn': 0.20,
'serious': 0.21,
'sad': 0.29,
'dark': 0.30,
'frustrated': 0.31,
'sentimental': 0.39,
'tender': 0.40,
'dreamy': 0.41,
'quiet': 0.49,
'satisfying': 0.50,
'soothing': 0.51,
'humorous': 0.59,
'fanciful': 0.60,
'graceful': 0.61,
'happy': 0.69,
'bright': 0.70,
'cheerful': 0.71,
'exciting': 0.79,
'dramatic': 0.80,
'passionate': 0.81,
'vigorous': 0.99,
'robust': 1.00,
'majestic': 1.01
}
def get_emotion_group(emotion):
for group, emotions in EMOTION_GROUPS.items():
if emotion in emotions:
return group
return None
def play_piano_for_emotion(emotion):
frequency = FREQUENCIES[emotion]
amplitude = AMPLITUDES[emotion]
pygame.mixer.init(frequency=frequency)
pygame.mixer.music.set_volume(amplitude)
pygame.mixer.music.load('path_to_piano_note.wav')
pygame.mixer.music.play()
pygame.time.wait(1000)
emotion_input = input("Enter an emotion: ").strip().lower()
group = get_emotion_group(emotion_input)
if group:
print(f"Detected Group: {group}")
play_piano_for_emotion(emotion_input)
else:
print("Unknown emotion.")