tonic.audio_transforms
#
Module Contents#
Classes#
Fix the length of a sample along a specified axis to a given length. |
|
Bin the given data along a specified axis at the specified new frequency. |
|
Interchange two axes of an array. |
|
Normalize the maximum amplitude of the input signal to a desired value, for instance the |
|
Normalize the maximum amplitude of the input signal while eliminating the outliers, to |
|
SOS filter. |
|
Butter filter. |
|
Butter filter bank. |
|
Butter filter bank. |
|
Butter filter bank with frequencies along the mel scale. |
|
Add nose to data. |
Functions#
|
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#
- 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#
- class tonic.audio_transforms.SwapAxes[source]#
Interchange two axes of an array.
- Parameters:
ax1 (int) – First axis
ax2 (int) – Second axis
- Returns:
array with interchanged axes
- Return type:
np.ndarray
- ax1: int = 0#
- ax2: int = 1#
- class tonic.audio_transforms.AmplitudeScale[source]#
Normalize the maximum amplitude of the input signal to a desired value, for instance the value can corespond to the mVolt equivalent of be the maximum loudness of the audio.
- Parameters:
data (np.ndarray) – input single- or multi-channel signal.
- Returns:
scaled version of the signal.
- Return type:
np.ndarray
- max_amplitude: float = 0.158#
- class tonic.audio_transforms.RobustAmplitudeScale[source]#
Normalize the maximum amplitude of the input signal while eliminating the outliers, to ensure that some very large outlier samples do not attenuate the majority of the samples.
- Paremeters:
max_robust_amplitude (float): maximum amplitude of non-outlier samples of the signal after robust scaling. outlier_percent (float, optional): percentage of the outlier in the data. Defaults to 0.01.
- Parameters:
data (np.ndarray) – input single- or multi-channel signal.
- Returns:
scaled version of the signal.
- Return type:
np.ndarray
- max_robust_amplitude: float = 0.158#
- outlier_percent: float = 0.01#
- 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#
- 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#
- 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#
- 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#
- 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) –
- 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#