General task of an application is to accumulate sound samples, received from the microphone, and saving the “useful” samples on a drive. “Usefulness” of a sample is determined by the classifier function. The function returns a boolean result, collected from the operation of a certain set of frequency filters, which are applied to the target audio stream; the function also considers the context of its work, namely, the duration of useful data stream from the moment of identification that the data stream is useful. Thus the useful data stream starts to buffer and will be stored until the moment of negative usefulness classification. A necessary and sufficient condition for saving the sample on a drive is overcoming the limit for the minimum possible time for any sample.
Classifier function will be presented additionally.
example of classification function:
import numpy as np
snd_device = pyaudio.PyAudio()
dev_info = snd_device.get_default_input_device_info()
sample_rate = int(dev_info.get('defaultSampleRate'))
def fast_filter(path_to_audiofile, energy_limit=0.02, LZCRB=0.02, HZCRB=0.15):
data, _ = librosa.load(path=path_to_audiofile, sr=sample_rate)
zcr = np.mean(librosa.feature.zero_crossing_rate(y=data))
energy = np.mean(librosa.feature.rmse(y=data))
return (energy >= energy_limit) and (LZCRB <= zcr) and (zcr <= HZCRB)