load_audio

ketos.data_handling.database_interface.load_audio(table, indices=None, table_annot=None, stack=False)[source]

Retrieve all the audio objects in a table or a subset specified by the index_list

Note that the method only can load audio representations recognized by Ketos. Available audio representations in Ketos are listed in Overview.

However, custom audio representations can easily be loaded with a few lines of code, using pytables directly:

>>> import tables 
>>> import MyCustomRepresentation 
>>> db = tables.open_file("my_db.h5") 
>>> tbl = db.get_node('/path/to/data/') 
>>> audio_obj = MyCustomRepresentation(data=tbl[0]['data']) 

Any other required parameters for the custom representation would need to be passed when calling the class.

Warnings: Loading all objects in a table might cause memory problems.

Args:
table: tables.Table

The table containing the audio objects

indices: list of ints or None

A list with the indices of the audio objects that will be retrieved. If set to None, loads all objects in the table.

table_annot: tables.Table

The table containing the annotations. If no such table is provided, the audio objects are still loaded, but without annotations.

stack: bool

Stack the audio objects into a single object

Returns:
audio_objs: list or instance of Waveform, MagSpectrogram, PowerSpectrogram, MelSpectrogram, CQTSpectrogram

Audio objects, or numpy array

Examples:
>>> from ketos.data_handling.database_interface import open_file, open_table, load_audio
>>> # Open a connection to the database.
>>> h5file = open_file("ketos/tests/assets/11x_same_spec.h5", 'r')
>>> # Open the tables in group_1
>>> tbl_data = open_table(h5file,"/group_1/table_data")
>>> tbl_annot = open_table(h5file,"/group_1/table_annot")    
>>> # Load the spectrograms stored on rows 0, 3 and 10, including their annotations
>>> from ketos.audio.spectrogram import MagSpectrogram
>>> selected_specs = load_audio(table=tbl_data, table_annot=tbl_annot, indices=[0,3,10])
>>> # The resulting list has the 3 spectrogram objects
>>> len(selected_specs)
3
>>> type(selected_specs[0])
<class 'ketos.audio.spectrogram.MagSpectrogram'>
>>>
>>> h5file.close()