-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprocess_datasets.py
More file actions
101 lines (92 loc) · 4.36 KB
/
process_datasets.py
File metadata and controls
101 lines (92 loc) · 4.36 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
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
96
97
98
99
100
101
import os
import pandas as pd
# 감정 레이블 매핑
emotion_mapping = {
"neutral": 0,
"happy": 1,
"sad": 2,
"angry": 3,
"fear": 4,
"disgust": 5
}
#데이터셋을 datasets/ 경로 아애레 다운 받았다는 가정 하에 실행합니다
# 데이터셋 경로 설정
ravdess_path = "datasets/RAVDESS/"
tess_path = "datasets/TESS/"
cremad_path = "datasets/CREMA-D/"
savee_path = "datasets/SAVEE/"
# 결과 저장 리스트
result = []
# RAVDESS 처리
for root, _, files in os.walk(ravdess_path):
for file in files:
if file.endswith(".wav"):
# 파일 이름에서 감정 번호 추출 (예: "03-01-01-01-01-01-01.wav")
parts = file.split("-")
if len(parts) > 2:
emotion_code = parts[2]
if emotion_code == "01":
result.append((os.path.join(root, file), emotion_mapping["neutral"]))
elif emotion_code == "03":
result.append((os.path.join(root, file), emotion_mapping["happy"]))
elif emotion_code == "04":
result.append((os.path.join(root, file), emotion_mapping["sad"]))
elif emotion_code == "05":
result.append((os.path.join(root, file), emotion_mapping["angry"]))
elif emotion_code == "06":
result.append((os.path.join(root, file), emotion_mapping["fear"]))
elif emotion_code == "07":
result.append((os.path.join(root, file), emotion_mapping["disgust"]))
# TESS 처리
for root, _, files in os.walk(tess_path):
for file in files:
if file.endswith(".wav"):
# 파일 경로에서 감정 추출 (예: "OAF_angry/OAF_back_angry.wav")
emotion = root.split("/")[-1].split("_")[-1].lower()
if emotion in emotion_mapping:
result.append((os.path.join(root, file), emotion_mapping[emotion]))
# CREMA-D 처리
for root, _, files in os.walk(cremad_path):
for file in files:
if file.endswith(".wav"):
# 파일 이름에서 감정 추출 (예: "1001_DFA_ANG_XX.wav")
parts = file.split("_")
if len(parts) > 2:
emotion = parts[2].lower()
if emotion == "neu":
result.append((os.path.join(root, file), emotion_mapping["neutral"]))
elif emotion == "hap":
result.append((os.path.join(root, file), emotion_mapping["happy"]))
elif emotion == "sad":
result.append((os.path.join(root, file), emotion_mapping["sad"]))
elif emotion == "ang":
result.append((os.path.join(root, file), emotion_mapping["angry"]))
elif emotion == "fea":
result.append((os.path.join(root, file), emotion_mapping["fear"]))
elif emotion == "dis":
result.append((os.path.join(root, file), emotion_mapping["disgust"]))
# SAVEE 처리
# for root, _, files in os.walk(savee_path):
# for file in files:
# if file.endswith(".wav"):
# # 파일 이름에서 감정 약어 추출 (예: "JK_a01.wav")
# emotion_code = file.split("_")[1][0:2] # 감정 코드가 두 글자일 가능성 포함
# if emotion_code == "n": # neutral
# result.append((os.path.join(root, file), emotion_mapping["neutral"]))
# elif emotion_code == "h": # happy
# result.append((os.path.join(root, file), emotion_mapping["happy"]))
# elif emotion_code == "sa": # sad
# result.append((os.path.join(root, file), emotion_mapping["sad"]))
# elif emotion_code == "a": # angry
# result.append((os.path.join(root, file), emotion_mapping["angry"]))
# elif emotion_code == "f": # fear
# result.append((os.path.join(root, file), emotion_mapping["fear"]))
# elif emotion_code == "d": # disgust
# result.append((os.path.join(root, file), emotion_mapping["disgust"]))
# # "su" (surprise)는 제외
# 결과를 DataFrame으로 변환
df = pd.DataFrame(result, columns=["file_path", "emotion_label"])
# CSV로 저장
output_csv_path = "datasets/emotion_melpath_dataset.csv"
df.to_csv(output_csv_path, index=False)
print(f"CSV 파일이 '{output_csv_path}'에 저장되었습니다.")