SelectionTableIterator

class ketos.audio.audio_loader.SelectionTableIterator(data_dir, selection_table, include_attrs=False, attrs=None, extract_dir='kt-tmp')[source]

Iterates over entries in a selection table.

Args:
data_dir: str

Path to top folder containing audio files, or a .tar archive file.

selection_table: pandas DataFrame

Selection table

include_attrs: bool

If True, load data from all attribute columns in the selection table. Default is False.

attrs: list(str)

Specify the names of the attribute columns that you wish to load data from. Overwrites include_attrs if specified. If None, all columns will be loaded provided that include_attrs=True.

extract_dir: str

Temporary directory for storing audio files extracted from a tar archive file. Only relevant if @data_dir points to a .tar file. The directory will be automatically created. If a directory already exists at the specified path, all its contents will be deleted. By default, audio files are extracted to the folder kt-tmp within the current working directory. Note that this folder must be deleted manually when it is no longer needed.

Methods

get_selection(n)

Returns the n-th audio selection in the table.

num()

Returns total number of selections.

reset()

Resets the selection generator to the beginning of the selection table.

get_selection(n)[source]

Returns the n-th audio selection in the table.

Args:
n: int

The index (0,1,2,…) of the desired selection.

Returns:
res: dict

The selection

num()[source]

Returns total number of selections.

Returns:
: int

Total number of selections.

reset()[source]

Resets the selection generator to the beginning of the selection table.