4
4
from torchaudio .datasets import iemocap
5
5
from torchaudio_unittest .common_utils import get_whitenoise , save_wav , TempDirMixin , TorchaudioTestCase
6
6
7
- LABELS = ["neu" , "hap" , "ang" , "sad" , "exc" , "xxx" ]
7
+ LABELS = ["neu" , "hap" , "ang" , "sad" , "exc" , "fru" , " xxx" ]
8
8
SAMPLE_RATE = 16000
9
9
10
10
@@ -21,8 +21,6 @@ def _save_wav(filepath: str, seed: int):
21
21
22
22
def _save_label (label_folder : str , filename : str , wav_stem : str ):
23
23
label = random .choice (LABELS )
24
- if label == "exc" :
25
- label = "hap"
26
24
line = f"[xxx]\t { wav_stem } \t { label } \t [yyy]"
27
25
filepath = os .path .join (label_folder , filename )
28
26
@@ -40,19 +38,22 @@ def _get_samples(dataset_dir: str, session: int):
40
38
os .makedirs (wav_folder , exist_ok = True )
41
39
os .makedirs (label_folder , exist_ok = True )
42
40
43
- samples = []
44
41
wav_stems = []
45
42
for i in range (5 ):
46
43
for g in ["F" , "M" ]:
47
- speaker = f"Ses0{ session } { g } "
48
- subfolder = f"{ speaker } _impro0{ i } "
49
- subfolder_path = os .path .join (wav_folder , subfolder )
50
- os .makedirs (subfolder_path , exist_ok = True )
51
-
52
- for j in range (5 ):
53
- wav_stem = f"{ subfolder } _F00{ j } "
54
- wav_stems .append (wav_stem )
55
-
44
+ for utt in ["impro" , "script" ]:
45
+ speaker = f"Ses0{ session } { g } "
46
+ subfolder = f"{ speaker } _{ utt } 0{ i } "
47
+ subfolder_path = os .path .join (wav_folder , subfolder )
48
+ os .makedirs (subfolder_path , exist_ok = True )
49
+
50
+ for j in range (5 ):
51
+ wav_stem = f"{ subfolder } _F00{ j } "
52
+ wav_stems .append (wav_stem )
53
+
54
+ all_samples = []
55
+ impro_samples = []
56
+ script_samples = []
56
57
wav_stems = sorted (wav_stems )
57
58
for wav_stem in wav_stems :
58
59
subfolder = wav_stem [:- 5 ]
@@ -64,31 +65,43 @@ def _get_samples(dataset_dir: str, session: int):
64
65
if label == "xxx" :
65
66
continue
66
67
sample = (wav , SAMPLE_RATE , wav_stem , label , speaker )
67
- samples .append (sample )
68
+ all_samples .append (sample )
69
+
70
+ if "impro" in subfolder :
71
+ impro_samples .append (sample )
72
+ else :
73
+ script_samples .append (sample )
68
74
69
- return samples
75
+ return all_samples , script_samples , impro_samples
70
76
71
77
72
78
def get_mock_dataset (dataset_dir : str ):
73
79
os .makedirs (dataset_dir , exist_ok = True )
74
80
75
- samples = []
81
+ all_samples = []
82
+ script_samples = []
83
+ impro_samples = []
76
84
for session in range (1 , 4 ):
77
- samples += _get_samples (dataset_dir , session )
78
- return samples
85
+ samples = _get_samples (dataset_dir , session )
86
+ all_samples += samples [0 ]
87
+ script_samples += samples [1 ]
88
+ impro_samples += samples [2 ]
89
+ return all_samples , script_samples , impro_samples
79
90
80
91
81
92
class TestIemocap (TempDirMixin , TorchaudioTestCase ):
82
93
root_dir = None
83
94
backend = "default"
84
95
85
- samples = []
96
+ all_samples = []
97
+ script_samples = []
98
+ impro_samples = []
86
99
87
100
@classmethod
88
101
def setUpClass (cls ):
89
102
cls .root_dir = cls .get_base_temp_dir ()
90
103
dataset_dir = os .path .join (cls .root_dir , "IEMOCAP" )
91
- cls .samples = get_mock_dataset (dataset_dir )
104
+ cls .all_samples , cls . script_samples , cls . impro_samples = get_mock_dataset (dataset_dir )
92
105
93
106
def _testIEMOCAP (self , dataset , samples ):
94
107
num_samples = 0
@@ -98,6 +111,14 @@ def _testIEMOCAP(self, dataset, samples):
98
111
99
112
assert num_samples == len (samples )
100
113
101
- def testIEMOCAPDataset (self ):
114
+ def testIEMOCAPFullDataset (self ):
102
115
dataset = iemocap .IEMOCAP (self .root_dir )
103
- self ._testIEMOCAP (dataset , self .samples )
116
+ self ._testIEMOCAP (dataset , self .all_samples )
117
+
118
+ def testIEMOCAPScriptedDataset (self ):
119
+ dataset = iemocap .IEMOCAP (self .root_dir , utterance_type = "scripted" )
120
+ self ._testIEMOCAP (dataset , self .script_samples )
121
+
122
+ def testIEMOCAPImprovisedDataset (self ):
123
+ dataset = iemocap .IEMOCAP (self .root_dir , utterance_type = "improvised" )
124
+ self ._testIEMOCAP (dataset , self .impro_samples )
0 commit comments