Skip to content

Commit

Permalink
set eaf MEDIA_FILE header
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasgautheron committed Jun 15, 2021
1 parent 7746f37 commit 51b5aa7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ChildProject/pipelines/eafbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ChildProject.pipelines.pipeline import Pipeline

def create_eaf(etf_path: str, id: str, output_dir: str,
recording_filename: str,
timestamps_list: list,
eaf_type: str, contxt_on: int, contxt_off: int,
template: str):
Expand Down Expand Up @@ -38,6 +39,9 @@ def create_eaf(etf_path: str, id: str, output_dir: str,

destination = os.path.join(output_dir, "{}.eaf".format(id))
os.makedirs(os.path.dirname(destination), exist_ok = True)

eaf.header['MEDIA_FILE'] = recording_filename

eaf.to_file(destination)
for i in eaf.get_tier_names():
print(i,":",eaf.get_annotation_data_for_tier(i))
Expand Down Expand Up @@ -97,18 +101,19 @@ def run(self, destination: str, segments: str,
segments = pd.read_csv(segments)

for recording_filename, segs in segments.groupby('recording_filename'):
recording_filename = os.path.splitext(recording_filename)[0]
output_filename = recording_filename + '_' + eaf_type + '_' + os.path.basename(template)
recording_prefix = os.path.splitext(recording_filename)[0]
output_filename = recording_prefix + '_' + eaf_type + '_' + os.path.basename(template)

# 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.
timestamps = [(on, off) for on, off in segs.loc[:, ['segment_onset', 'segment_offset']].values]

output_dir = os.path.join(destination, recording_filename)
output_dir = os.path.join(destination, recording_prefix)

create_eaf(
etf_path,
output_filename,
output_dir,
recording_filename,
timestamps,
eaf_type,
context_onset,
Expand All @@ -124,7 +129,7 @@ def setup_parser(parser):
parser.add_argument("--destination", help = "eaf destination")
parser.add_argument('--segments', help = 'path to the input segments dataframe', required = True)
# TODO: add other options here such as high-volubility, energy, etc.?
parser.add_argument('--eaf-type', help = 'eaf-type', choices = ['random', 'periodic', 'high-volubility'], required = True)
parser.add_argument('--eaf-type', help = 'eaf-type', choices = ['random', 'periodic', 'high-volubility', 'energy-detection'], required = True)
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)
parser.add_argument('--context-onset', help = 'context onset and segment offset difference in milliseconds, 0 for no introductory context', type = int, default = 0)
parser.add_argument('--context-offset', help = 'context offset and segment offset difference in milliseconds, 0 for no outro context', type = int, default = 0)
2 changes: 2 additions & 0 deletions tests/test_eaf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ def test_periodic():
segments[['segment_onset', 'segment_offset']].sort_values(['segment_onset', 'segment_offset']).reset_index(drop = True),
sampler.segments[['segment_onset', 'segment_offset']].sort_values(['segment_onset', 'segment_offset']).reset_index(drop = True)
)

assert eaf.header['MEDIA_FILE'] == 'sound.wav'

0 comments on commit 51b5aa7

Please sign in to comment.