Skip to content

Commit 51b5aa7

Browse files
set eaf MEDIA_FILE header
1 parent 7746f37 commit 51b5aa7

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

ChildProject/pipelines/eafbuilder.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from ChildProject.pipelines.pipeline import Pipeline
99

1010
def create_eaf(etf_path: str, id: str, output_dir: str,
11+
recording_filename: str,
1112
timestamps_list: list,
1213
eaf_type: str, contxt_on: int, contxt_off: int,
1314
template: str):
@@ -38,6 +39,9 @@ def create_eaf(etf_path: str, id: str, output_dir: str,
3839

3940
destination = os.path.join(output_dir, "{}.eaf".format(id))
4041
os.makedirs(os.path.dirname(destination), exist_ok = True)
42+
43+
eaf.header['MEDIA_FILE'] = recording_filename
44+
4145
eaf.to_file(destination)
4246
for i in eaf.get_tier_names():
4347
print(i,":",eaf.get_annotation_data_for_tier(i))
@@ -97,18 +101,19 @@ def run(self, destination: str, segments: str,
97101
segments = pd.read_csv(segments)
98102

99103
for recording_filename, segs in segments.groupby('recording_filename'):
100-
recording_filename = os.path.splitext(recording_filename)[0]
101-
output_filename = recording_filename + '_' + eaf_type + '_' + os.path.basename(template)
104+
recording_prefix = os.path.splitext(recording_filename)[0]
105+
output_filename = recording_prefix + '_' + eaf_type + '_' + os.path.basename(template)
102106

103107
# TODO: This list of timestamps as tuples might not be ideal/should perhaps be optimized, but I am just replicating the original eaf creation code here.
104108
timestamps = [(on, off) for on, off in segs.loc[:, ['segment_onset', 'segment_offset']].values]
105109

106-
output_dir = os.path.join(destination, recording_filename)
110+
output_dir = os.path.join(destination, recording_prefix)
107111

108112
create_eaf(
109113
etf_path,
110114
output_filename,
111115
output_dir,
116+
recording_filename,
112117
timestamps,
113118
eaf_type,
114119
context_onset,
@@ -124,7 +129,7 @@ def setup_parser(parser):
124129
parser.add_argument("--destination", help = "eaf destination")
125130
parser.add_argument('--segments', help = 'path to the input segments dataframe', required = True)
126131
# TODO: add other options here such as high-volubility, energy, etc.?
127-
parser.add_argument('--eaf-type', help = 'eaf-type', choices = ['random', 'periodic', 'high-volubility'], required = True)
132+
parser.add_argument('--eaf-type', help = 'eaf-type', choices = ['random', 'periodic', 'high-volubility', 'energy-detection'], required = True)
128133
parser.add_argument('--template', help = 'Which ACLEW templates (basic, native or non-native); otherwise, the path to the etf et pfsx templates, without the extension.', required = True)
129134
parser.add_argument('--context-onset', help = 'context onset and segment offset difference in milliseconds, 0 for no introductory context', type = int, default = 0)
130135
parser.add_argument('--context-offset', help = 'context offset and segment offset difference in milliseconds, 0 for no outro context', type = int, default = 0)

tests/test_eaf.py

+2
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ def test_periodic():
4242
segments[['segment_onset', 'segment_offset']].sort_values(['segment_onset', 'segment_offset']).reset_index(drop = True),
4343
sampler.segments[['segment_onset', 'segment_offset']].sort_values(['segment_onset', 'segment_offset']).reset_index(drop = True)
4444
)
45+
46+
assert eaf.header['MEDIA_FILE'] == 'sound.wav'

0 commit comments

Comments
 (0)