Commit 0f505de1 authored by Jan Kiene's avatar Jan Kiene
Browse files

Merge branch 'padding-between-files-for-concatenation' into 'main'

Add keys to allow padding between files in concatenation

See merge request !168
parents a0c18bdd cb0323c4
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -114,6 +114,10 @@ input:
    ### the individual items (concatenate_input: false) after previous pre-processing step
    ### Horizontally concatenate input items into one long file; default = false
    # concatenate_input: true
    ### if concatenation is applied, the following two keys can be used to add zeros before or after the items
    ### duration is specified in miliseconds
    # silence_pre: 2000
    # silence_post: 2000
    ### Specify the concatenation order in a list of strings. If not specified, the concatenation order would be
    ### as per the filesystem on the users' device
    ### Should only be used if concatenate_input = true
+2 −2
Original line number Diff line number Diff line
@@ -166,8 +166,8 @@ def write(
def concat(
    in_filenames: list,
    out_file: str,
    silence_pre: Optional[int] = 0,
    silence_post: Optional[int] = 0,
    silence_pre: int = 0,
    silence_post: int = 0,
    in_fs: Optional[int] = 48000,
    num_channels: Optional[int] = None,
    pad_noise: Optional[bool] = False,
+2 −0
Original line number Diff line number Diff line
@@ -201,6 +201,8 @@ def get_preprocessing_2(cfg: TestConfig) -> dict:
                "in_mask": pre2_cfg.get("mask", None),
                "multiprocessing": cfg.multiprocessing,
                "repeat_signal": pre2_cfg.get("repeat_signal", False),
                "silence_pre": pre2_cfg.get("silence_pre", 0),
                "silence_post": pre2_cfg.get("silence_post", 0),
            }
        )
    )
+14 −0
Original line number Diff line number Diff line
@@ -163,11 +163,25 @@ def concat_setup(cfg: TestConfig, chain, logger: logging.Logger):
    tmp_audio = audio.fromtype(cfg_pre2.in_fmt)
    tmp_num_chans = tmp_audio.num_channels

    # convert from milisecs to samples
    silence_pre = 0
    silence_post = 0
    if cfg_pre2.silence_pre != 0 or silence_post != 0:
        if cfg_pre2.in_fs is None:
            raise ValueError(
                "silence_pre and silence_post can only be non-zero if you provide the sampling rate in the input section!"
            )

        silence_pre = int(cfg_pre2.silence_pre / 1000 * cfg_pre2.in_fs)
        silence_post = int(cfg_pre2.silence_post / 1000 * cfg_pre2.in_fs)

    cfg.splits, fs = concat(
        cfg.items_list,
        cfg.concat_file,
        in_fs=cfg_pre2.in_fs,
        num_channels=tmp_num_chans,
        silence_pre=silence_pre,
        silence_post=silence_post,
    )

    # save item naming for splits naming in the end