audformat.testing provides the possibility to create small and well defined audformat.Database objects that are of interest for creating unit tests.

In order to use it you first have to import it explicitly:

import audformat.testing


audformat.testing.create_db(minimal=False, data=None)[source]

Create test database.

Creates a test database called unittest with a filewise and segmented table.

  • minimal (bool) – create minimal database without tables

  • data (Optional[Dict[str, Union[Series, DataFrame]]]) – create tables from pandas objects

Return type



database object


audformat.testing.add_table(db, table_id, index_type, *, columns=None, num_files=5, num_segments_per_file=5, file_duration='5s', file_root='audio', p_none=None, split_id=None, media_id=None)[source]

Adds a table with random values.

By default adds one column for every scheme in the database. To create a specific set of columns use columns. If a media_id is passed, the file format will be determined from there. Otherwise WAV is used.

  • db (Database) – a database

  • table_id (str) – ID of table that will be created

  • index_type (str) – the index type, see audformat.define.IndexType for available index types

  • columns (Union[str, Sequence[str], Dict[str, Union[str, Tuple[Optional[str], Optional[str]]]], None]) – a list of scheme_ids or a dictionary with column names as keys and tuples of (scheme_id, rater_id) as values. None values are allowed

  • num_files (Union[int, Sequence[int]]) – by default files are named '001', '002', etc. up the number of files. For a different ordering a sequence of integers can be passed

  • num_segments_per_file (int) – number of segments per file (only applies to to segmented table)

  • file_duration (Union[str, Timedelta]) – the file duration

  • file_root (str) – file sub directory

  • p_none (Optional[float]) – probability to draw invalid values

  • split_id (Optional[str]) – optional split ID

  • media_id (Optional[str]) – optional media ID

Return type



table object


audformat.testing.create_audio_files(db, root=None, *, sample_generator=None, sampling_rate=16000, channels=1, file_duration='60s')[source]

Create audio files for a database.

By default empty files are created. A sample generator function can be passed to generate the samples. The function gets as input a time stamp and should create a sample in the amplitude range [-1..1].

  • db (Database) – a database

  • sample_generator (Optional[Callable[[float], float]]) – sample generator

  • sampling_rate (int) – sampling rate in Hz

  • channels (int) – number of channels

  • file_duration (Union[str, Timedelta]) – file duration