@@ -7,6 +7,12 @@ def write_emodb_csv(emotions=["sad", "neutral", "happy"], train_name="train_emo.
77 test_name = "test_emo.csv" , train_size = 0.8 , verbose = 1 ):
88 """
99 Reads speech emodb dataset from directory and write it to a metadata CSV file.
10+ params:
11+ emotions (list): list of emotions to read from the folder, default is ['sad', 'neutral', 'happy']
12+ train_name (str): the output csv filename for training data, default is 'train_emo.csv'
13+ test_name (str): the output csv filename for testing data, default is 'test_emo.csv'
14+ train_size (float): the ratio of splitting training data, default is 0.8 (80% Training data and 20% testing data)
15+ verbose (int/bool): verbositiy level, 0 for silence, 1 for info, default is 1
1016 """
1117 target = {"path" : [], "emotion" : []}
1218 categories = {
@@ -50,65 +56,62 @@ def write_tess_ravdess_csv(emotions=["sad", "neutral", "happy"], train_name="tra
5056 test_name = "test_tess_ravdess.csv" , verbose = 1 ):
5157 """
5258 Reads speech TESS & RAVDESS datasets from directory and write it to a metadata CSV file.
59+ params:
60+ emotions (list): list of emotions to read from the folder, default is ['sad', 'neutral', 'happy']
61+ train_name (str): the output csv filename for training data, default is 'train_tess_ravdess.csv'
62+ test_name (str): the output csv filename for testing data, default is 'test_tess_ravdess.csv'
63+ verbose (int/bool): verbositiy level, 0 for silence, 1 for info, default is 1
5364 """
54- target = {"path" : [], "emotion" : []}
55- categories = {
56- 1 : "neutral" ,
57- 2 : "calm" ,
58- 3 : "happy" ,
59- 4 : "sad" ,
60- 5 : "angry" ,
61- 6 : "fear" ,
62- 7 : "disgust" ,
63- 8 : "ps"
64- }
65- # delete not specified emotions
66- categories_reversed = { v : k for k , v in categories .items () }
67- for emotion , code in categories_reversed .items ():
68- if emotion not in emotions :
69- del categories [code ]
70- # for training speech directory
71- for _ , category in categories .items ():
65+ train_target = {"path" : [], "emotion" : []}
66+ test_target = {"path" : [], "emotion" : []}
67+
68+ for category in emotions :
69+ # for training speech directory
7270 for i , path in enumerate (glob .glob (f"data/training/Actor_*/*_{ category } .wav" )):
73- target ["path" ].append (path )
74- target ["emotion" ].append (category )
71+ train_target ["path" ].append (path )
72+ train_target ["emotion" ].append (category )
7573 if verbose :
7674 print (f"[TESS&RAVDESS] There are { i } training audio files for category:{ category } " )
77- pd .DataFrame (target ).to_csv (train_name )
78- target = {"path" : [], "emotion" : []}
79- # for validation speech directory
80- for _ , category in categories .items ():
75+
76+ # for validation speech directory
8177 for i , path in enumerate (glob .glob (f"data/validation/Actor_*/*_{ category } .wav" )):
82- target ["path" ].append (path )
83- target ["emotion" ].append (category )
78+ test_target ["path" ].append (path )
79+ test_target ["emotion" ].append (category )
8480 if verbose :
8581 print (f"[TESS&RAVDESS] There are { i } testing audio files for category:{ category } " )
86- pd .DataFrame (target ).to_csv (test_name )
82+ pd .DataFrame (test_target ).to_csv (test_name )
83+ pd .DataFrame (train_target ).to_csv (train_name )
8784
8885
89- def write_custom_csv (emotions = ['sad' , 'neutral' , 'happy' ], train_name = "train_custom.csv" , test_name = "test_custom.csv" ):
90- categories = {
91- 1 : "sad" ,
92- 2 : "neutral" ,
93- 3 : "happy"
94- }
95- # delete not specified emotions
96- categories_reversed = { v : k for k , v in categories .items () }
97- for emotion , code in categories_reversed .items ():
98- if emotion not in emotions :
99- del categories [code ]
100- target = {"path" : [], "emotion" : []}
101- for code , category in categories .items ():
102- for file in glob .glob (f"data/train-custom/*_{ category } .wav" ):
103- target ["path" ].append (file )
104- target ["emotion" ].append (category )
105- if target ["path" ]:
106- pd .DataFrame (target ).to_csv (train_name )
86+ def write_custom_csv (emotions = ['sad' , 'neutral' , 'happy' ], train_name = "train_custom.csv" , test_name = "test_custom.csv" ,
87+ verbose = 1 ):
88+ """
89+ Reads Custom Audio data from data/*-custom and then writes description files (csv)
90+ params:
91+ emotions (list): list of emotions to read from the folder, default is ['sad', 'neutral', 'happy']
92+ train_name (str): the output csv filename for training data, default is 'train_custom.csv'
93+ test_name (str): the output csv filename for testing data, default is 'test_custom.csv'
94+ verbose (int/bool): verbositiy level, 0 for silence, 1 for info, default is 1
95+ """
96+ train_target = {"path" : [], "emotion" : []}
97+ test_target = {"path" : [], "emotion" : []}
98+ for category in emotions :
99+ # train data
100+ for i , file in enumerate (glob .glob (f"data/train-custom/*_{ category } .wav" )):
101+ train_target ["path" ].append (file )
102+ train_target ["emotion" ].append (category )
103+ if verbose :
104+ print (f"[Custom Dataset] There are { i } training audio files for category:{ category } " )
105+
106+ # test data
107+ for i , file in enumerate (glob .glob (f"data/test-custom/*_{ category } .wav" )):
108+ test_target ["path" ].append (file )
109+ test_target ["emotion" ].append (category )
110+ if verbose :
111+ print (f"[Custom Dataset] There are { i } testing audio files for category:{ category } " )
112+
113+ if train_target ["path" ]:
114+ pd .DataFrame (train_target ).to_csv (train_name )
107115
108- target = {"path" : [], "emotion" : []}
109- for code , category in categories .items ():
110- for file in glob .glob (f"data/test-custom/*_{ category } .wav" ):
111- target ["path" ].append (file )
112- target ["emotion" ].append (category )
113- if target ["path" ]:
114- pd .DataFrame (target ).to_csv (test_name )
116+ if test_target ["path" ]:
117+ pd .DataFrame (test_target ).to_csv (test_name )
0 commit comments