FeatureExtractor

class audioflux.FeatureExtractor(transforms, num=None, radix2_exp=12, samplate=32000, low_fre=None, high_fre=None, bin_per_octave=12, slide_length=None, scale_type=SpectralFilterBankScaleType.LINEAR, wavelet_type=WaveletContinueType.MORSE)

Batch feature extraction

Parameters
transforms: list or str

Transform type.

Supported: bft/nsgt/cwt/pwt/cqt/st/fst/dwt/wpt

num: int or None

Number of frequency bins to generate.

  • only BFT/NSGT/CWT/PWT available

  • cqt is a fixed value of 84

  • dwt see: DWT default value

  • wpt see: WPT default value

radix2_exp: int

fft_length=2**radix2_exp

samplate: int

Sampling rate of the incoming audio.

low_fre: float or None

Lowest frequency.

high_fre: float or None

Highest frequency.

bin_per_octave: int

Number of bins per octave.

slide_length: int or None

Window sliding length.

scale_type: SpectralFilterBankScaleType

Spectral filter bank type. It determines the type of spectrogram.

See: type.SpectralFilterBankScaleType

wavelet_type: WaveletContinueType

Wavelet Type

  • only CWT available

See: type.WaveletContinueType

Examples

Get a 880Hz’s audio file

>>> import audioflux as af
>>> sample_path = af.utils.sample_path('880')
>>> audio_arr, sr = af.read(sample_path)

Create FeatureExtractor object and extract spectrogram

>>> from audioflux.type import SpectralFilterBankScaleType
>>> fa_obj = af.FeatureExtractor(transforms=['bft', 'cwt', 'cqt'], samplate=sr, radix2_exp=12,
>>>                              scale_type=SpectralFilterBankScaleType.OCTAVE)
>>> spec_result = fa_obj.spectrogram(audio_arr, is_continue=True)

Extract spectral/xxcc/deconv

>>> spectral_result = fa_obj.spectral(spec_result, spectral='flux',
>>>                                   spectral_kw={'is_positive': True})
>>> xxcc_result = fa_obj.xxcc(spec_result, cc_num=13)
>>> deconv_result = fa_obj.deconv(spec_result)

Methods

deconv(spec_result[, spec_convert])

Deconv feature

spectral(spec_result, spectral[, ...])

spectral related features

spectrogram(data_arr[, is_continue])

Get the spectrogram of transforms

xxcc(spec_result[, cc_num, rectify_type, ...])

cepstral coefficients

spectrogram(data_arr, is_continue=False)

Get the spectrogram of transforms

Parameters
data_arr: np.ndarray [shape=(n,)] or list(np.ndarray [shape=(n,)])

Input audio datas

is_continue: bool

Calculate continuous 2D(nsgt/cwt/pwt/st/fst/dwt/wpt) spectrogram.

Calculate the cwt every fft/2, then divide the x-axis of each cwt into four parts, and take the middle two parts for splicing (the first part will be spliced with the first part of the first cwt, and the tail will be spliced with the last part of the last cwt).

If True, then calculate continuous 2D spectrogram. If False, the 2D spectrogram can only calculate fft_length(2**radix2_exp) data

Returns
out: FeatureResult

spectrogram data

xxcc(spec_result, cc_num=13, rectify_type=CepstralRectifyType.LOG, spec_convert=<ufunc 'absolute'>)

cepstral coefficients

See: XXCC

Parameters
spec_result: FeatureResult

spectrogram result

cc_num: int

xxcc num, usually set to 13, 20 or 40

rectify_type: CepstralRectifyType

rectify type

spec_convert: function

Operations on spectrogram data

Returns
out: FeatureResult

xxcc data

deconv(spec_result, spec_convert=<ufunc 'absolute'>)

Deconv feature

See: Deconv

Parameters
spec_result: FeatureResult

spectrogram result

spec_convert: function

Operations on spectrogram data

Returns
out: FeatureResult

deconv data

spectral(spec_result, spectral, spectral_kw=None, spec_convert=<ufunc 'absolute'>)

spectral related features

Parameters
spec_result: FeatureResult

spectrogram result

spectral: str

spectral feature name

See: Spectral

spectral_kw: dict or None

spectral feature parameters

See: Spectral

spec_convert: function

Operations on spectrogram data

Returns
out: FeatureResult

spectral data