:py:mod:`tonic.audio_transforms`
================================

.. py:module:: tonic.audio_transforms


Module Contents
---------------

Classes
~~~~~~~

.. autoapisummary::

   tonic.audio_transforms.FixLength
   tonic.audio_transforms.Bin
   tonic.audio_transforms.SwapAxes
   tonic.audio_transforms.AmplitudeScale
   tonic.audio_transforms.RobustAmplitudeScale
   tonic.audio_transforms.SOSFilter
   tonic.audio_transforms.ButterFilter
   tonic.audio_transforms.ButterFilterBank
   tonic.audio_transforms.LinearButterFilterBank
   tonic.audio_transforms.MelButterFilterBank
   tonic.audio_transforms.AddNoise



Functions
~~~~~~~~~

.. autoapisummary::

   tonic.audio_transforms.normalize



.. py:class:: FixLength


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

   :param length: Desired length of the sample
   :type length: int
   :param axis: Dimension along which the length needs to be fixed.. Defaults to 1.
   :type axis: int, optional

   :param data: data sample
   :type data: np.ndarray

   :returns: fixed length data sample
   :rtype: np.ndarray

   .. py:attribute:: length
      :type: int

      

   .. py:attribute:: axis
      :type: int
      :value: 1

      

   .. py:method:: __call__(data: numpy.ndarray) -> numpy.ndarray



.. py:class:: Bin


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

   :param orig_freq: Sampling frequency of the given data stream
   :type orig_freq: float
   :param new_freq: Desired frequency after binning
   :type new_freq: float
   :param axis: Axis along which the data needs to be binned
   :type axis: int

   :param data: data sample
   :type data: np.ndarray

   :returns: binned data sample
   :rtype: np.ndarray

   .. py:attribute:: orig_freq
      :type: float

      

   .. py:attribute:: new_freq
      :type: float

      

   .. py:attribute:: axis
      :type: int

      

   .. py:method:: __call__(data: numpy.ndarray) -> numpy.ndarray



.. py:class:: SwapAxes


   Interchange two axes of an array.

   :param ax1: First axis
   :type ax1: int
   :param ax2: Second axis
   :type ax2: int

   :returns: array with interchanged axes
   :rtype: np.ndarray

   .. py:attribute:: ax1
      :type: int
      :value: 0

      

   .. py:attribute:: ax2
      :type: int
      :value: 1

      

   .. py:method:: __call__(data: numpy.ndarray) -> numpy.ndarray



.. py:class:: AmplitudeScale


   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.

   :param data: input single- or multi-channel signal.
   :type data: np.ndarray

   :returns: scaled version of the signal.
   :rtype: np.ndarray

   .. py:attribute:: max_amplitude
      :type: float
      :value: 0.158

      

   .. py:method:: __call__(data: numpy.ndarray) -> numpy.ndarray



.. py:class:: RobustAmplitudeScale


   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.
   :param data: input single- or multi-channel signal.
   :type data: np.ndarray

   :returns: scaled version of the signal.
   :rtype: np.ndarray

   .. py:attribute:: max_robust_amplitude
      :type: float
      :value: 0.158

      

   .. py:attribute:: outlier_percent
      :type: float
      :value: 0.01

      

   .. py:method:: __call__(data: numpy.ndarray) -> numpy.ndarray



.. py:class:: SOSFilter


   SOS filter.

   :param coeffs: coefficients of the second order filter
   :param axis: Axis along with the filter needs to be applied
   :param See https:
   :type See https: //docs.scipy.org/doc/scipy/reference/generated/scipy.signal.sosfilt.html for more details

   .. py:attribute:: coeffs
      :type: numpy.ndarray

      

   .. py:attribute:: axis
      :type: int

      

   .. py:method:: __call__(signal)



.. py:class:: ButterFilter


   Butter filter.

   :param order: Order of filter to be used
   :param freq: Frequency for the filter (float or (float, float))
   :param analog: True if analog filter
   :param btype: Filter type, {‘lowpass’, ‘highpass’, ‘bandpass’, ‘bandstop’}
   :param rectify: If true, the output is the absolute value of the filtered output
   :param axis: Axis along which the filter needs to be applied
   :param See https:
   :type See https: //docs.scipy.org/doc/scipy/reference/generated/scipy.signal.butter.html#scipy.signal.butter for more details on parameters.

   .. py:attribute:: order
      :type: int

      

   .. py:attribute:: freq
      :type: float | tuple[float, float]

      

   .. py:attribute:: analog
      :type: bool

      

   .. py:attribute:: btype
      :type: str

      

   .. py:attribute:: rectify
      :type: bool

      

   .. py:attribute:: axis
      :type: int

      

   .. py:method:: __post_init__()


   .. py:method:: __call__(data: numpy.ndarray) -> numpy.ndarray



.. py:class:: ButterFilterBank


   Butter filter bank.

   :param order: Order of filter to be used
   :param freq: Frequency for the filter (float or (float, float))
   :param rectify: If true, the output is the absolute value of the filtered output
   :param axis: Axis along which the filter needs to be applied
   :param analog: If true, the filter will be analog. False by default
   :param See https:
   :type See https: //docs.scipy.org/doc/scipy/reference/generated/scipy.signal.butter.html#scipy.signal.butter for more details on parameters.

   .. py:attribute:: order
      :type: int

      

   .. py:attribute:: freq
      :type: list[tuple[float, float]]

      

   .. py:attribute:: rectify
      :type: bool

      

   .. py:attribute:: axis
      :type: int

      

   .. py:attribute:: analog
      :type: bool
      :value: False

      

   .. py:method:: __post_init__()


   .. py:method:: __call__(data)



.. py:class:: LinearButterFilterBank


   Butter filter bank.

   :param order: Order of filter to be used
   :param low_freq: Lower/cutoff frequency the filter (float or (float, float))
   :param sampling_freq: Sampling frequency of the signal, also serves as higher frequency of the filter bank.
   :param analog: True if analog filter
   :param rectify: If true, the output is the absolute value of the filtered output
   :param axis: Axis along which the filter needs to be applied
   :param See https:
   :type See https: //docs.scipy.org/doc/scipy/reference/generated/scipy.signal.butter.html#scipy.signal.butter for more details on parameters.

   .. py:attribute:: order
      :type: int
      :value: 2

      

   .. py:attribute:: low_freq
      :type: float
      :value: 100

      

   .. py:attribute:: sampling_freq
      :type: float
      :value: 16000

      

   .. py:attribute:: analog
      :type: bool
      :value: False

      

   .. py:attribute:: num_filters
      :type: int
      :value: 64

      

   .. py:attribute:: rectify
      :type: bool
      :value: True

      

   .. py:attribute:: axis
      :type: int

      

   .. py:method:: compute_freq_bands()


   .. py:method:: __post_init__()


   .. py:method:: __call__(data)



.. py:class:: MelButterFilterBank


   Bases: :py:obj:`LinearButterFilterBank`

   Butter filter bank with frequencies along the mel scale.

   :param order: Order of filter to be used
   :param low_freq: Lower/cutoff frequency the filter (float or (float, float))
   :param sampling_freq: Sampling frequency of the signal, also serves as higher frequency of the filter bank.
   :param analog: True if analog filter
   :param rectify: If true, the output is the absolute value of the filtered output
   :param axis: Axis along which the filter needs to be applied
   :param See https:
   :type See https: //docs.scipy.org/doc/scipy/reference/generated/scipy.signal.butter.html#scipy.signal.butter for more details on parameters.

   .. py:method:: hz2mel(freq)
      :staticmethod:


   .. py:method:: mel2hz(freq)
      :staticmethod:


   .. py:method:: compute_freq_bands()



.. py:class:: AddNoise


   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.

   .. py:attribute:: dataset
      :type: collections.abc.Iterator

      

   .. py:attribute:: snr
      :type: float

      

   .. py:attribute:: normed
      :type: bool
      :value: True

      

   .. py:method:: get_noise_sample(sample_len: int) -> numpy.ndarray

      Get a random noise sample from the dataset.


   .. py:method:: __call__(signal)



.. py:function:: normalize(signal)

   Normalize the signal.


