# Presentation Attack Detection in Voice Biometrics¶

This package is an extension of the bob.pad.base presentation attack detection (PAD) framework package for voice biometrics.

### Extractors¶

class bob.pad.voice.extractor.LBPs(features_processor, n_lbps=2, lbp_neighbors=16, lbp_to_average=False, lbp_uniform=False, lbp_radius=1, lbp_circular=True, lbp_elbp_type='regular', band_ratios=True, **kwargs)

Extractor that computes histograms of LBP features from a textogram, which, in turn, is computed by a cepstral or spectral extractor passed as an argument.

compute_lbps(data)[source]
get_features(input_data, annotations)[source]
class bob.pad.voice.extractor.Ratios(features_processor, n_bands=5, **kwargs)
compute_ratios(data)[source]
class bob.pad.voice.extractor.VectorsRatios(features_processor, n_bands=5, feature_vector_length=50, vectors_overlap=5, **kwargs)
compute_ratios(data)[source]
class bob.pad.voice.extractor.GLCMs(features_processor, n_glcms=1, offset_vector=[[0, 1], [1, 0]], properties=True, **kwargs)

Extractor that computes histograms of LBP features from a textogram, which, in turn, is computed by a cepstral or spectral extractor passed as an argument.

compute_glcms(data)[source]
get_features(input_data, annotations)[source]
class bob.pad.voice.extractor.SpectrogramExtended(win_length_ms=20.0, win_shift_ms=10.0, n_filters=40, f_min=0.0, f_max=4000, pre_emphasis_coef=1.0, mel_scale=True, rect_filter=False, inverse_filter=False, normalize_spectrum=False, log_filter=True, energy_filter=False, energy_bands=True, vad_filter='trim_silence', normalize_feature_vector=False, **kwargs)

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

compute_spectrogram(rate, data)[source]
normalize_features(features)[source]
class bob.pad.voice.extractor.LBPHistograms(features_processor, n_lbp_histograms=2, lbp_neighbors=16, lbp_to_average=False, lbp_uniform=False, lbp_radius=1, lbp_circular=True, lbp_elbp_type='regular', histograms_for_rows=False, band_ratios=True, **kwargs)

Extractor that computes histograms of LBP features from a textogram, which, in turn, is computed by a cepstral or spectral extractor passed as an argument.

compute_histograms(lbp_wrapper, lbpimages)[source]
class bob.pad.voice.extractor.DummyTF(**kwargs)

This class can be used as a simple preprocessor (reads data only) and a dummy extractor (reads saved data)

class bob.pad.voice.extractor.AudioTFExtractor(feature_layer='fc1', **kwargs)

Parameters:

feature_layer: The layer to be used as features. Possible values are fc1 or ‘fc2’.

load(extractor_file)[source]

Loads the parameters required for feature extraction from the extractor file. This function usually is only useful in combination with the train() function. In this base class implementation, it does nothing.

Parameters:

extractor_filestr

The file to read the extractor from.

train(**kwargs)[source]

This function can be overwritten to train the feature extractor. If you do this, please also register the function by calling this base class constructor and enabling the training by requires_training = True.

Parameters:

training_data[object] or [[object]]

A list of preprocessed data that can be used for training the extractor. Data will be provided in a single list, if split_training_features_by_client = False was specified in the constructor, otherwise the data will be split into lists, each of which contains the data of a single (training-)client.

extractor_filestr

The file to write. This file should be readable with the load() function.

### Algorithms¶

class bob.pad.voice.algorithm.GMM(normalize_features=False, number_of_gaussians=512, kmeans_training_iterations=25, gmm_training_iterations=10, training_threshold=0.0005, variance_threshold=0.0005, update_weights=True, update_means=True, update_variances=True, responsibility_threshold=0, INIT_SEED=2015, requires_projector_training=False, **kwargs)

Trains Logistical Regression classifier and projects testing dat on it.

load_projector(projector_file)[source]

Loads the parameters required for feature projection from file. This function usually is useful in combination with the train_projector() function. In this base class implementation, it does nothing.

Please register performs_projection = True in the constructor to enable this function.

Parameters:

projector_filestr

The file to read the projector from.

project(feature) → projected[source]

Projects the given feature into GMM space.

Parameters:

feature

The 1D feature to be projected.

Returns:

projected

The feature projected into GMM space.

project_feature(feature)[source]
read_gmm_stats(gmm_stats_file)[source]

save_gmms(projector_file)[source]

Save projector to file

score(toscore)[source]

Returns the difference between log likelihoods of being real or attack

score_for_multiple_projections(toscore)[source]

Returns the difference between log likelihoods of being real or attack

train_gmm(array)[source]
train_projector(training_features, projector_file)[source]

This function can be overwritten to train the feature projector. If you do this, please also register the function by calling this base class constructor and enabling the training by requires_projector_training = True.

Parameters:

training_features[object] or [[object]]

A list of extracted features that can be used for training the projector. Features will be provided in a single list

projector_filestr

The file to write. This file should be readable with the load_projector() function.

class bob.pad.voice.algorithm.LogRegr(use_PCA_training=False, normalize_features=False, **kwargs)

Trains Logistical Regression classifier and projects testing dat on it.

enroll(enroll_features)[source]

We do no enrollment here

load_projector(projector_file)[source]

Loads the parameters required for feature projection from file. This function usually is useful in combination with the train_projector() function. In this base class implementation, it does nothing.

Please register performs_projection = True in the constructor to enable this function.

Parameters:

projector_filestr

The file to read the projector from.

project(feature) → projected[source]

Projects the given feature into Fisher space.

Parameters:

feature

The 1D feature to be projected.

Returns:

projected

The feature projected into Fisher space.

project_feature(feature)[source]
score(toscore)[source]

Returns the output of a classifier

score_for_multiple_projections(toscore)[source]

scorescore_for_multiple_projections(toscore) -> score

This function will compute the score for a list of objects in toscore. It must be overwritten by derived classes.

Parameters:

toscore[object]

A list of objects to compute the score for.

Returns:

scorefloat

A score value for the object toscore.

train_projector(training_features, projector_file)[source]

This function can be overwritten to train the feature projector. If you do this, please also register the function by calling this base class constructor and enabling the training by requires_projector_training = True.

Parameters:

training_features[object] or [[object]]

A list of extracted features that can be used for training the projector. Features will be provided in a single list

projector_filestr

The file to write. This file should be readable with the load_projector() function.

class bob.pad.voice.algorithm.TensorflowEval(architecture_name='mlp', input_shape=[200, 81], network_size=60, normalization_file=None, **kwargs)

This class is for evaluating data stored in tensorflow tfrecord format using a pre-trained LSTM model.

load_projector(projector_file)[source]

Loads the parameters required for feature projection from file. This function usually is useful in combination with the train_projector() function. In this base class implementation, it does nothing.

Please register performs_projection = True in the constructor to enable this function.

Parameters:

projector_filestr

The file to read the projector from.

normalize_data(features)[source]
project(feature) → projected[source]

This function will project the given feature. It is assured that the load_projector() was called once before the project function is executed.

Parameters:

featureobject

The feature to be projected.

Returns:

projectedobject

The projected features. Must be writable with the write_feature() function and readable with the read_feature() function.

project_feature(feature)[source]
restore_trained_model(projector_file)[source]
score(toscore)[source]

Returns the evarage value of the probe

score_for_multiple_projections(toscore)[source]

scorescore_for_multiple_projections(toscore) -> score

Returns:

scorefloat

A score value for the object toscore.

### Databases¶

class bob.pad.voice.database.PadVoiceFile(client_id, path, attack_type=None, file_id=None)

A simple base class that defines basic properties of File object for the use in PAD experiments

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

bob.pad.voice.database.VoicePadFile
class bob.pad.voice.database.ASVspoofPadDatabase(protocol='CM', **kwargs)

Implements verification API for querying ASVspoof database.

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

Returns a set of Files for the specific query by the user.

Keyword Parameters:

groups

One of the groups (‘dev’, ‘eval’, ‘train’) or a tuple with several of them. If ‘None’ is given (this is the default), it is considered the same as a tuple with all possible values.

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.

purposes

The purposes can be either ‘real’ or ‘attack’.

model_ids

This parameter is not supported in this implementation.

Returns: A set of Files with the specified properties.

class bob.pad.voice.database.ASVspoof2017PadDatabase(protocol='competition', **kwargs)

Implements verification API for querying ASVspoof2017 database.

convert_purposes(names, low_level_names, high_level_names)[source]

Converts purposes names from a low level to high level API

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

Returns a set of Files for the specific query by the user.

Keyword Parameters:

groups

One of the groups (‘dev’, ‘eval’, ‘train’) or a tuple with several of them. If ‘None’ is given (this is the default), it is considered the same as a tuple with all possible values.

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.

purposes

The purposes can be either ‘real’ or ‘attack’.

model_ids

This parameter is not supported in this implementation.

Returns: A set of Files with the specified properties.

class bob.pad.voice.database.AVspoofPadDatabase(protocol='grandtest', **kwargs)

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.pad.base.database.PadFile

The file for which annotations should be returned.

Returns:

annotsdict or None

The annotations for the file, if available.

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

Returns a set of Files for the specific query by the user.

Keyword Parameters:

groups

One of the groups (‘dev’, ‘eval’, ‘train’) or a tuple with several of them. If ‘None’ is given (this is the default), it is considered the same as a tuple with all possible values.

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.

purposes

The purposes can be either ‘real’ or ‘attack’.

model_ids

This parameter is not supported in this implementation.

Returns: A set of Files with the specified properties.

class bob.pad.voice.database.VoicePAPadDatabase(protocol='grandtest', **kwargs)

Implements verification API for querying voicePA database.

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

Returns a set of Files for the specific query by the user.

Keyword Parameters:

groups

One of the groups (‘train’, ‘dev’, ‘eval’) or a tuple with several of them. If ‘None’ is given (this is the default), it is considered the same as a tuple with all possible values.

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.

purposes

The purposes can be either ‘real’ or ‘attack’.

model_ids

This parameter is not supported in this implementation.

Returns: A set of Files with the specified properties.