Module thunderlab.convertdata

Command line script for converting, downsampling, renaming and merging data files.

convertdata -o test.wav test.raw

converts 'test.raw' to 'test.wav'.

The script reads all input files with dataloader.load_data(), combines the audio and marker data, and writes them along with the metadata to an output file using datawriter.write_data(). Thus, all formats supported by these functions and the installed python audio modules are supported.

Run

convertdata -l

for a list of supported output file formats and

convertdata -f wav -l

for a list of supported encodings for a given output format.

Running

convertdata --help

prints

usage: convertdata [-h] [--version] [-v] [-l] [-f FORMAT] [-e ENCODING] [-s SCALE] [-u [THRESH]] [-U [THRESH]]
                   [-d FAC] [-c CHANNELS] [-a KEY=VALUE] [-r KEY] [-n NUM] [-o OUTPATH]
                   [file ...]

Convert, downsample, rename, and merge data files.

positional arguments:
  file          one or more input files to be combined into a single output file

options:
  -h, --help    show this help message and exit
  --version     show program's version number and exit
  -v            print debug output
  -l            list supported file formats and encodings
  -f FORMAT     audio format of output file
  -e ENCODING   audio encoding of output file
  -s SCALE      scale the data by factor SCALE
  -u [THRESH]   unwrap clipped data with threshold (default is 0.5) and divide by two
  -U [THRESH]   unwrap clipped data with threshold (default is 0.5) and clip
  -d FAC        downsample by integer factor
  -c CHANNELS   comma and dash separated list of channels to be saved (first channel is 0)
  -a KEY=VALUE  add key-value pairs to metadata. Keys can have section names separated by "."
  -r KEY        remove keys from metadata. Keys can have section names separated by "."
  -n NUM        merge NUM input files into one output file
  -o OUTPATH    path or filename of output file. Metadata keys enclosed in curly braces will be replaced by their
                values from the input file

version 1.12.0 by Benda-Lab (2020-2024)

Functions

def check_format(format)

Check whether requested audio format is valid and supported.

If the format is not available print an error message on console.

Parameters

format : string
Audio format to be checked.

Returns

valid : bool
True if the requested audio format is valid.
def list_formats_encodings(data_format)

List available formats or encodings.

Parameters

data_format : None or str
If provided, list encodings for this data format.
def main(*cargs)

Command line script for converting, downsampling, renaming and merging data files.

Parameters

cargs : list of strings
Command line arguments as returned by sys.argv[1:].