tonic.audio_transforms#

Module Contents#

Classes#

FixLength

Fix the length of a sample along a specified axis to a given length.

Bin

Bin the given data along a specified axis at the specified new frequency.

SOSFilter

SOS filter.

ButterFilter

Butter filter.

ButterFilterBank

Butter filter bank.

LinearButterFilterBank

Butter filter bank.

MelButterFilterBank

Butter filter bank with frequencies along the mel scale.

AddNoise

Add nose to data.

Functions#

normalize(signal)

Normalize the signal.

class tonic.audio_transforms.FixLength[source]#

Fix the length of a sample along a specified axis to a given length.

Parameters:
  • length (int) – Desired length of the sample

  • axis (int, optional) – Dimension along which the length needs to be fixed.. Defaults to 1.

  • data (np.ndarray) – data sample

Returns:

fixed length data sample

Return type:

np.ndarray

length: int#
axis: int = 1#
__call__(data: numpy.ndarray) numpy.ndarray[source]#
Parameters:

data (numpy.ndarray) –

Return type:

numpy.ndarray

class tonic.audio_transforms.Bin[source]#

Bin the given data along a specified axis at the specified new frequency.

Parameters:
  • orig_freq (float) – Sampling frequency of the given data stream

  • new_freq (float) – Desired frequency after binning

  • axis (int) – Axis along which the data needs to be binned

  • data (np.ndarray) – data sample

Returns:

binned data sample

Return type:

np.ndarray

orig_freq: float#
new_freq: float#
axis: int#
__call__(data: numpy.ndarray) numpy.ndarray[source]#
Parameters:

data (numpy.ndarray) –

Return type:

numpy.ndarray

class tonic.audio_transforms.SOSFilter[source]#

SOS filter.

Parameters:
  • coeffs – coefficients of the second order filter

  • axis – Axis along with the filter needs to be applied

  • https (See) –

coeffs: numpy.ndarray#
axis: int#
__call__(signal)[source]#
class tonic.audio_transforms.ButterFilter[source]#

Butter filter.

Parameters:
  • order – Order of filter to be used

  • freq – Frequency for the filter (float or (float, float))

  • analog – True if analog filter

  • btype – Filter type, {‘lowpass’, ‘highpass’, ‘bandpass’, ‘bandstop’}

  • rectify – If true, the output is the absolute value of the filtered output

  • axis – Axis along which the filter needs to be applied

  • https (See) –

order: int#
freq: Union[float, Tuple[float, float]]#
analog: bool#
btype: str#
rectify: bool#
axis: int#
__post_init__()[source]#
__call__(data: numpy.ndarray) numpy.ndarray[source]#
Parameters:

data (numpy.ndarray) –

Return type:

numpy.ndarray

class tonic.audio_transforms.ButterFilterBank[source]#

Butter filter bank.

Parameters:
  • order – Order of filter to be used

  • freq – Frequency for the filter (float or (float, float))

  • rectify – If true, the output is the absolute value of the filtered output

  • axis – Axis along which the filter needs to be applied

  • analog – If true, the filter will be analog. False by default

  • https (See) –

order: int#
freq: List[Tuple[float, float]]#
rectify: bool#
axis: int#
analog: bool = False#
__post_init__()[source]#
__call__(data)[source]#
class tonic.audio_transforms.LinearButterFilterBank[source]#

Butter filter bank.

Parameters:
  • order – Order of filter to be used

  • low_freq – Lower/cutoff frequency the filter (float or (float, float))

  • sampling_freq – Sampling frequency of the signal, also serves as higher frequency of the filter bank.

  • analog – True if analog filter

  • rectify – If true, the output is the absolute value of the filtered output

  • axis – Axis along which the filter needs to be applied

  • https (See) –

order: int = 2#
low_freq: float = 100#
sampling_freq: float = 16000#
analog: bool = False#
num_filters: int = 64#
rectify: bool = True#
axis: int#
compute_freq_bands()[source]#
__post_init__()[source]#
__call__(data)[source]#
class tonic.audio_transforms.MelButterFilterBank[source]#

Bases: LinearButterFilterBank

Butter filter bank with frequencies along the mel scale.

Parameters:
  • order – Order of filter to be used

  • low_freq – Lower/cutoff frequency the filter (float or (float, float))

  • sampling_freq – Sampling frequency of the signal, also serves as higher frequency of the filter bank.

  • analog – True if analog filter

  • rectify – If true, the output is the absolute value of the filtered output

  • axis – Axis along which the filter needs to be applied

  • https (See) –

static hz2mel(freq)[source]#
static mel2hz(freq)[source]#
compute_freq_bands()[source]#
class tonic.audio_transforms.AddNoise[source]#

Add nose to data.

Params:
dataset:

A dataset object that returns a tuple when iterated over the first element of which is the audio signal to be used for noise.

snr:

Desired signal to noise ratio in dB

normed:

If set to false, the signal max value will not be normalized. True by default.

dataset: Iterator#
snr: float#
normed: bool = True#
get_noise_sample(sample_len: int) numpy.ndarray[source]#

Get a random noise sample from the dataset.

Parameters:

sample_len (int) –

Return type:

numpy.ndarray

__call__(signal)[source]#
tonic.audio_transforms.normalize(signal)[source]#

Normalize the signal.