Temporal

class audioflux.Temporal(frame_length=2048, slide_length=512, window_type=WindowType.HANN)

Temporal feature

Parameters
frame_length: int

frame length

slide_length: int

sliding length

window_type: WindowType

Window type for each frame.

See: type.WindowType

Examples

Read 220Hz audio data

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

Create Temporal and extract feature

>>> temp_obj = af.Temporal(frame_length=2048, slide_length=512)
>>> feature_dic = temp_obj.temporal(data_arr=audio_arr, has_rms=True, has_energy=True, has_zcr=True)
>>> energy_arr = feature_dic['energy_arr']
>>> rms_arr = feature_dic['rms_arr']
>>> zcr_arr = feature_dic['zcr_arr']

Show Temporal plot

>>> from matplotlib import pyplot as plt
>>> times = np.arange(rms_arr.shape[-1]) * (temp_obj.slide_length / sr)
>>> fig, axes = plt.subplots(nrows=4, sharex=True)
>>> af.display.fill_wave(audio_arr, axes=axes[0])
>>> af.display.fill_plot(times, energy_arr, axes=axes[1], label='Energy')
>>> af.display.fill_plot(times, rms_arr, axes=axes[2], label='RMS')
>>> af.display.fill_plot(times, zcr_arr, axes=axes[3], label='ZCR')
../_images/temporal-1.png

Methods

cal_time_length(data_length)

Calculate the length of a frame from audio data.

get_data(data_arr)

Get energy/rms/zeroCrossRate feature

temporal(data_arr[, has_energy, has_rms, ...])

Get energy/rms/zeroCrossRate feature

cal_time_length(data_length)

Calculate the length of a frame from audio data.

Parameters
data_length: int

The length of the data to be calculated.

Returns
out: int
temporal(data_arr, has_energy=False, has_rms=False, has_zcr=False, has_m=False)

Get energy/rms/zeroCrossRate feature

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

Input audio data

has_energy: bool

Whether to return energy feature

has_rms: bool

Whether to return rms feature

has_zcr: bool

Whether to return ZeroCrossRate feature

has_m: bool

Whether to return m feature

Returns
feature_dic: dict

energy_arr: np.ndarray [shape=(…, time)] if has_energy is True return energy_arr

rms_arr: np.ndarray [shape=(…, time)] if has_rms is True return rms_arr

zcr_arr: np.ndarray [shape=(…, time)] if has_zcr is True return zcr_arr

m_arr: np.ndarray [shape=(…, time, frame)] if has_m is True return m_arr

get_data(data_arr)

Get energy/rms/zeroCrossRate feature

Warning

This function will be deprecated, please use temporal instead.

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

Input audio data

Returns
energy_arr: np.ndarray [shape=(…, time)]

energy feature

rms_arr: np.ndarray [shape=(…, time)]

rms feature

zcr_arr: np.ndarray [shape=(…, time)]

Zero Cross Rate feature

m_arr: np.ndarray [shape=(…, time, frame)]