Commit fe7c7bf3 authored by Vinit Veera's avatar Vinit Veera
Browse files

Rename the generated conditions at the end of the processing steps.

parent 3b7084e0
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -49,6 +49,10 @@ output_path: ".../tmp_output"
# input_select:
#  - "48kHz"

### Include the condition number in the item name; default = false
### for e.g. abcxyz.wav --> abcxyz.cXX.wav
# condition_in_output_filename: true

################################################
### Input configuration
################################################
+4 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ from ivas_processing_scripts.processing.processing import (
    preprocess_2,
    preprocess_background_noise,
    process_item,
    rename_generated_conditions,
    reorder_items_list,
    reverse_process_2,
)
@@ -175,6 +176,9 @@ def main(args):
        if hasattr(cfg, "preprocessing_2"):
            reverse_process_2(cfg, logger)

        if cfg.condition_in_output_filename:
            rename_generated_conditions(cfg.output_path)

    # copy configuration to output directory
    with open(cfg.output_path.joinpath(f"{cfg.name}.yml"), "w") as f:
        yaml.safe_dump(cfg._yaml_dump, f)
+1 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ DEFAULT_CONFIG = {
        "mask": None,
        "limit": False,
    },
    "condition_in_output_filename": False,
}
DEFAULT_CONFIG_EVS = {
    "cod": {
+20 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ from abc import ABC, abstractmethod
from itertools import repeat
from pathlib import Path
from shutil import copyfile
import re
from typing import Iterable, Optional, Union
from warnings import warn

@@ -560,3 +561,22 @@ def multiple_of_frame_size(
                warn(
                    f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of frame length (20 ms)."
                )


def rename_generated_conditions(output_path: Path):
    """
    Rename the output files. Only renames the files in directories that contain "cXX" in thier names.
    The "XX" in "cXX" stands for the condition number, for example "c01"

    Parameters
    ----------
    output_path: Path
        Path to output directory
    """
    directory = output_path
    pattern = re.compile(r"^c\d{2}$")
    for subdirectory in directory.iterdir():
        if subdirectory.is_dir() and pattern.match(subdirectory.name):
            for file_path in subdirectory.iterdir():
                new_filename = f"{file_path.stem}.{subdirectory.name}{file_path.suffix}"
                file_path.rename(subdirectory / new_filename)