Tools implemented in bob.bio.spear

Summary

Databases

bob.bio.spear.database.ASVspoofBioDatabase(…)

Implements verification API for querying ASVspoof database.

bob.bio.spear.database.AVspoofBioDatabase(…)

Implements verification API for querying AVspoof database.

bob.bio.spear.database.MobioBioDatabase([…])

Implements verification API for querying Mobio database.

bob.bio.spear.database.VoicePABioDatabase(…)

Implements verification API for querying VoicePA database.

Speech Preprocessors

bob.bio.spear.preprocessor.Base(**kwargs)

Performs color space adaptations and data type corrections for the given image

bob.bio.spear.preprocessor.Energy_2Gauss([…])

Extracts the Energy

bob.bio.spear.preprocessor.Energy_Thr([…])

VAD based on the thresholded energy

bob.bio.spear.preprocessor.Mod_4Hz([…])

VAD based on the modulation of the energy around 4 Hz and the energy

bob.bio.spear.preprocessor.External([…])

Uses external VAD and converts it to fit the format used by Spear

Voice Feature Extractors

bob.bio.spear.extractor.Cepstral([…])

Extracts the Cepstral features

bob.bio.spear.extractor.SPROFeatures([…])

Extracts the Cepstral features

bob.bio.spear.extractor.HTKFeatures([…])

Extracts the Cepstral features

Databases

Feature extraction tools

class bob.bio.spear.database.AudioBioFile(client_id, path, file_id, **kwargs)

Bases: bob.bio.base.database.BioFile

load(directory=None, extension='.wav')[source]

Loads the data at the specified location and using the given extension. Override it if you need to load differently.

Parameters
  • directory (str, optional) – If not empty or None, this directory is prefixed to the final file destination

  • extension (str, optional) – If not empty or None, this extension is suffixed to the final file destination

Returns

The loaded data (normally numpy.ndarray).

Return type

object

class bob.bio.spear.database.MobioBioDatabase(original_directory=None, original_extension=None, annotation_directory=None, annotation_extension='.pos', **kwargs)

Bases: bob.bio.base.database.ZTBioDatabase

Implements verification API for querying Mobio database.

annotations(file)[source]

Returns the annotations for the given File object, if available. You need to override this method in your high-level implementation. If your database does not have annotations, it should return None.

Parameters:

filebob.bio.base.database.BioFile

The file for which annotations should be returned.

Returns:

annotsdict or None

The annotations for the file, if available.

model_ids_with_protocol(groups = None, protocol = None, **kwargs) → ids[source]

Returns a list of model ids for the given groups and given protocol.

Parameters:

groupsone or more of ('world', 'dev', 'eval')

The groups to get the model ids for.

protocol: a protocol name

Returns:

ids[int] or [str]

The list of (unique) model ids for the given groups.

objects(groups=None, protocol=None, purposes=None, model_ids=None, **kwargs)[source]

This function returns a list of bob.bio.base.database.BioFile objects or the list of objects which inherit from this class. Returned files fulfill the given restrictions.

Keyword parameters:

groupsstr or [str]

The groups of which the clients should be returned. Usually, groups are one or more elements of (‘world’, ‘dev’, ‘eval’)

protocol

The protocol for which the clients should be retrieved. The protocol is dependent on your database. If you do not have protocols defined, just ignore this field.

purposesstr or [str]

The purposes for which File objects should be retrieved. Usually, purposes are one of (‘enroll’, ‘probe’).

model_ids[various type]

The model ids for which the File objects should be retrieved. What defines a ‘model id’ is dependent on the database. In cases, where there is only one model per client, model ids and client ids are identical. In cases, where there is one model per file, model ids and file ids are identical. But, there might also be other cases.

tmodel_ids_with_protocol(protocol=None, groups=None, **kwargs)[source]

This function returns the ids of the T-Norm models of the given groups for the given protocol.

Keyword parameters:

groupsstr or [str]

The groups of which the model ids should be returned. Usually, groups are one or more elements of (‘dev’, ‘eval’)

protocolstr

The protocol for which the model ids should be retrieved. The protocol is dependent on your database. If you do not have protocols defined, just ignore this field.

tobjects(groups=None, protocol=None, model_ids=None, **kwargs)[source]

This function returns the File objects of the T-Norm models of the given groups for the given protocol and the given model ids.

Keyword parameters:

groupsstr or [str]

The groups of which the model ids should be returned. Usually, groups are one or more elements of (‘dev’, ‘eval’)

protocolstr

The protocol for which the model ids should be retrieved. The protocol is dependent on your database. If you do not have protocols defined, just ignore this field.

model_ids[various type]

The model ids for which the File objects should be retrieved. What defines a ‘model id’ is dependent on the database. In cases, where there is only one model per client, model ids and client ids are identical. In cases, where there is one model per file, model ids and file ids are identical. But, there might also be other cases.

zobjects(groups=None, protocol=None, **kwargs)[source]

This function returns the File objects of the Z-Norm impostor files of the given groups for the given protocol.

Keyword parameters:

groupsstr or [str]

The groups of which the model ids should be returned. Usually, groups are one or more elements of (‘dev’, ‘eval’)

protocolstr

The protocol for which the model ids should be retrieved. The protocol is dependent on your database. If you do not have protocols defined, just ignore this field.

class bob.bio.spear.database.ASVspoofBioDatabase(**kwargs)

Bases: bob.bio.base.database.BioDatabase

Implements verification API for querying ASVspoof database.

annotations(file)[source]

Returns the annotations for the given File object, if available. You need to override this method in your high-level implementation. If your database does not have annotations, it should return None.

Parameters:

filebob.bio.base.database.BioFile

The file for which annotations should be returned.

Returns:

annotsdict or None

The annotations for the file, if available.

model_ids_with_protocol(groups = None, protocol = None, **kwargs) → ids[source]

Returns a list of model ids for the given groups and given protocol.

Parameters:

groupsone or more of ('world', 'dev', 'eval')

The groups to get the model ids for.

protocol: a protocol name

Returns:

ids[int] or [str]

The list of (unique) model ids for the given groups.

objects(protocol=None, purposes=None, model_ids=None, groups=None, **kwargs)[source]

This function returns a list of bob.bio.base.database.BioFile objects or the list of objects which inherit from this class. Returned files fulfill the given restrictions.

Keyword parameters:

groupsstr or [str]

The groups of which the clients should be returned. Usually, groups are one or more elements of (‘world’, ‘dev’, ‘eval’)

protocol

The protocol for which the clients should be retrieved. The protocol is dependent on your database. If you do not have protocols defined, just ignore this field.

purposesstr or [str]

The purposes for which File objects should be retrieved. Usually, purposes are one of (‘enroll’, ‘probe’).

model_ids[various type]

The model ids for which the File objects should be retrieved. What defines a ‘model id’ is dependent on the database. In cases, where there is only one model per client, model ids and client ids are identical. In cases, where there is one model per file, model ids and file ids are identical. But, there might also be other cases.

class bob.bio.spear.database.AVspoofBioDatabase(**kwargs)

Bases: bob.bio.base.database.BioDatabase

Implements verification API for querying AVspoof database.

annotations(file)[source]

Returns the annotations for the given File object, if available. You need to override this method in your high-level implementation. If your database does not have annotations, it should return None.

Parameters:

filebob.bio.base.database.BioFile

The file for which annotations should be returned.

Returns:

annotsdict or None

The annotations for the file, if available.

model_ids_with_protocol(groups = None, protocol = None, **kwargs) → ids[source]

Returns a list of model ids for the given groups and given protocol.

Parameters:

groupsone or more of ('world', 'dev', 'eval')

The groups to get the model ids for.

protocol: a protocol name

Returns:

ids[int] or [str]

The list of (unique) model ids for the given groups.

objects(protocol=None, purposes=None, model_ids=None, groups=None, **kwargs)[source]

This function returns a list of bob.bio.base.database.BioFile objects or the list of objects which inherit from this class. Returned files fulfill the given restrictions.

Keyword parameters:

groupsstr or [str]

The groups of which the clients should be returned. Usually, groups are one or more elements of (‘world’, ‘dev’, ‘eval’)

protocol

The protocol for which the clients should be retrieved. The protocol is dependent on your database. If you do not have protocols defined, just ignore this field.

purposesstr or [str]

The purposes for which File objects should be retrieved. Usually, purposes are one of (‘enroll’, ‘probe’).

model_ids[various type]

The model ids for which the File objects should be retrieved. What defines a ‘model id’ is dependent on the database. In cases, where there is only one model per client, model ids and client ids are identical. In cases, where there is one model per file, model ids and file ids are identical. But, there might also be other cases.

class bob.bio.spear.database.VoicePABioDatabase(**kwargs)

Bases: bob.bio.base.database.BioDatabase

Implements verification API for querying VoicePA database.

annotations(file)[source]

Returns the annotations for the given File object, if available. You need to override this method in your high-level implementation. If your database does not have annotations, it should return None.

Parameters:

filebob.bio.base.database.BioFile

The file for which annotations should be returned.

Returns:

annotsdict or None

The annotations for the file, if available.

model_ids_with_protocol(groups = None, protocol = None, **kwargs) → ids[source]

Returns a list of model ids for the given groups and given protocol.

Parameters:

groupsone or more of ('world', 'dev', 'eval')

The groups to get the model ids for.

protocol: a protocol name

Returns:

ids[int] or [str]

The list of (unique) model ids for the given groups.

objects(protocol=None, purposes=None, model_ids=None, groups=None, **kwargs)[source]

This function returns a list of bob.bio.base.database.BioFile objects or the list of objects which inherit from this class. Returned files fulfill the given restrictions.

Keyword parameters:

groupsstr or [str]

The groups of which the clients should be returned. Usually, groups are one or more elements of (‘world’, ‘dev’, ‘eval’)

protocol

The protocol for which the clients should be retrieved. The protocol is dependent on your database. If you do not have protocols defined, just ignore this field.

purposesstr or [str]

The purposes for which File objects should be retrieved. Usually, purposes are one of (‘enroll’, ‘probe’).

model_ids[various type]

The model ids for which the File objects should be retrieved. What defines a ‘model id’ is dependent on the database. In cases, where there is only one model per client, model ids and client ids are identical. In cases, where there is one model per file, model ids and file ids are identical. But, there might also be other cases.

class bob.bio.spear.database.ASVspoof2017BioDatabase(**kwargs)

Bases: bob.bio.base.database.BioDatabase

Implements verification API for querying ASVspoof2017 database.

annotations(file)[source]

Returns the annotations for the given File object, if available. You need to override this method in your high-level implementation. If your database does not have annotations, it should return None.

Parameters:

filebob.bio.base.database.BioFile

The file for which annotations should be returned.

Returns:

annotsdict or None

The annotations for the file, if available.

model_ids_with_protocol(groups = None, protocol = None, **kwargs) → ids[source]

Returns a list of model ids for the given groups and given protocol.

Parameters:

groupsone or more of ('world', 'dev', 'eval')

The groups to get the model ids for.

protocol: a protocol name

Returns:

ids[int] or [str]

The list of (unique) model ids for the given groups.

objects(protocol=None, purposes=None, model_ids=None, groups=None, **kwargs)[source]

This function returns a list of bob.bio.base.database.BioFile objects or the list of objects which inherit from this class. Returned files fulfill the given restrictions.

Keyword parameters:

groupsstr or [str]

The groups of which the clients should be returned. Usually, groups are one or more elements of (‘world’, ‘dev’, ‘eval’)

protocol

The protocol for which the clients should be retrieved. The protocol is dependent on your database. If you do not have protocols defined, just ignore this field.

purposesstr or [str]

The purposes for which File objects should be retrieved. Usually, purposes are one of (‘enroll’, ‘probe’).

model_ids[various type]

The model ids for which the File objects should be retrieved. What defines a ‘model id’ is dependent on the database. In cases, where there is only one model per client, model ids and client ids are identical. In cases, where there is one model per file, model ids and file ids are identical. But, there might also be other cases.

Preprocessors

class bob.bio.spear.preprocessor.Base(**kwargs)

Bases: bob.bio.base.preprocessor.Preprocessor

Performs color space adaptations and data type corrections for the given image

read_data(data_file) → data[source]

Reads the preprocessed data from file. In this base class implementation, it uses bob.bio.base.load() to do that. If you have different format, please overwrite this function.

Parameters:

data_filestr or bob.io.base.HDF5File

The file open for reading or the name of the file to read from.

Returns:

dataobject (usually numpy.ndarray)

The preprocessed data read from file.

write_data(data, data_file, compression=0)[source]

Writes the given preprocessed data to a file with the given name.

class bob.bio.spear.preprocessor.Energy_2Gauss(max_iterations=10, convergence_threshold=0.0005, variance_threshold=0.0005, win_length_ms=20.0, win_shift_ms=10.0, smoothing_window=10, **kwargs)

Bases: bob.bio.spear.preprocessor.Base

Extracts the Energy

class bob.bio.spear.preprocessor.Energy_Thr(win_length_ms=20.0, win_shift_ms=10.0, smoothing_window=10, ratio_threshold=0.15, **kwargs)

Bases: bob.bio.spear.preprocessor.Base

VAD based on the thresholded energy

class bob.bio.spear.preprocessor.Mod_4Hz(max_iterations=10, convergence_threshold=0.0005, variance_threshold=0.0005, win_length_ms=20.0, win_shift_ms=10.0, smoothing_window=10, n_filters=40, f_min=0.0, f_max=4000, pre_emphasis_coef=1.0, ratio_threshold=0.1, **kwargs)

Bases: bob.bio.spear.preprocessor.Base

VAD based on the modulation of the energy around 4 Hz and the energy

averaging(list_1s_shift)[source]
bandpass_firwin(ntaps, lowcut, highcut, fs, window='hamming')[source]
mod_4hz(rate_wavsample)[source]

Computes and returns the 4Hz modulation energy features for the given input wave file

modulation_4hz(filtering_res, rate_wavsample)[source]
pass_band_filtering(energy_bands, fs)[source]
class bob.bio.spear.preprocessor.External(win_length_ms=20.0, win_shift_ms=10.0, **kwargs)

Bases: bob.bio.spear.preprocessor.Base

Uses external VAD and converts it to fit the format used by Spear

use_existing_vad(inArr, vad_file)[source]

Extractors

Feature extraction tools

class bob.bio.spear.extractor.Cepstral(win_length_ms=20, win_shift_ms=10, n_filters=24, dct_norm=False, f_min=0.0, f_max=4000, delta_win=2, mel_scale=True, with_energy=True, with_delta=True, with_delta_delta=True, n_ceps=19, pre_emphasis_coef=0.95, features_mask=array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59]), normalize_flag=True, **kwargs)

Bases: bob.bio.base.extractor.Extractor

Extracts the Cepstral features

normalize_features(params)[source]
class bob.bio.spear.extractor.HTKFeatures(features_mask=array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59]), normalize_flag=True, **kwargs)

Bases: bob.bio.base.extractor.Extractor

Extracts the Cepstral features

HTKReader(input_file)[source]
normalize_features(params)[source]
class bob.bio.spear.extractor.SPROFeatures(features_mask=array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59]), normalize_flag=True, **kwargs)

Bases: bob.bio.base.extractor.Extractor

Extracts the Cepstral features

SPRORead(input_file)[source]
normalize_features(params)[source]
class bob.bio.spear.extractor.CepstralExtended(win_length_ms=20.0, win_shift_ms=10.0, n_filters=40, f_min=0.0, f_max=8000, pre_emphasis_coef=1.0, mel_scale=True, rect_filter=False, inverse_filter=False, delta_win=2, n_ceps=19, dct_norm=False, ssfc_features=False, scfc_features=False, scmc_features=False, with_delta=True, with_delta_delta=True, with_energy=False, normalize_spectrum=False, keep_only_deltas=True, log_filter=True, energy_filter=False, vad_filter='no_filter', normalize_feature_vector=False, **kwargs)

Bases: bob.bio.base.extractor.Extractor

Extract energy bands from spectrogram and VAD labels based on the modulation of the energy around 4 Hz

compute_ceps(rate, data)[source]
normalize_features(features)[source]
class bob.bio.spear.extractor.CQCCFeatures(split_training_data_by_client=False, features_mask=array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]), **kwargs)

Bases: bob.bio.base.preprocessor.Preprocessor, bob.bio.base.extractor.Extractor

This class should be used as a preprocessor (converts matlab data into HDF5) and an extractor (reads saved data)

Converts pre-computed with Matlab CQCC features into numpy array suitable for Bob-based experiments. CQCC features are obtained using CQCC Matlab toolkit from http://audio.eurecom.fr/content/software The features are originally proposed in the following paper: Todisco, Massimiliano; Delgado, Héctor; Evans, Nicholas “Articulation rate filtering of CQCC features for automatic speaker verification”, INTERSPEECH 2016, Annual Conference of the International Speech Communication Association, September 8-12, 2016, San Francisco, USA

read_matlab_files(biofile, directory, extension)[source]

Read pre-computed CQCC Matlab features here