API reference
- audio_purifier.purify(audio: str | BinaryIO | ndarray, export_format: str | None = 'wav', vad_parameters: dict | VadOptions | None = None, sampling_rate: int = 16000) BytesIO | None
Purify an audio file: remove silences and return a BytesIO object.
- Parameters:
audio – Path to the input file (or a file-like object), or the audio waveform.
export_format – Default result file format is ‘wav’, require Pydub to convert to other format.
vad_parameters – Dictionary of Silero VAD parameters or VadOptions class (see available parameters and default values in the class VadOptions).
sampling_rate – Resample the audio to this sample rate.
- Returns:
BytesIO object that contains the processed audio, and None in case the initial audio contains full of silences.
- audio_purifier.purify_and_export(audio: str | BinaryIO | ndarray, export: str | BinaryIO, export_format: str | None = 'wav', vad_parameters: dict | VadOptions | None = None, sampling_rate: int = 16000) bool
Purify an audio file and then export it to export field.
- Parameters:
audio – Path to the input file (or a file-like object), or the audio waveform.
export – Path or byte-like object that the result should be saved to.
export_format – Default result file format is ‘wav’, require Pydub to convert to other format. Will be overridden if export exist.
vad_parameters – Dictionary of Silero VAD parameters or VadOptions class (see available parameters and default values in the class VadOptions).
sampling_rate – Resample the audio to this sample rate.
- Returns:
True if the audio is successfully processed and written to the export file, otherwise False.
Vad options
- class audio_purifier.VadOptions(threshold: float = 0.5, min_speech_duration_ms: int = 250, max_speech_duration_s: float = inf, min_silence_duration_ms: int = 2000, window_size_samples: int = 1024, speech_pad_ms: int = 400)
VAD options.
- threshold
Speech threshold. Silero VAD outputs speech probabilities for each audio chunk, probabilities ABOVE this value are considered as SPEECH. It is better to tune this parameter for each dataset separately, but “lazy” 0.5 is pretty good for most datasets.
- Type:
float
- min_speech_duration_ms
Final speech chunks shorter min_speech_duration_ms are thrown out.
- Type:
int
- max_speech_duration_s
Maximum duration of speech chunks in seconds. Chunks longer than max_speech_duration_s will be split at the timestamp of the last silence that lasts more than 100ms (if any), to prevent aggressive cutting. Otherwise, they will be split aggressively just before max_speech_duration_s.
- Type:
float
- min_silence_duration_ms
In the end of each speech chunk wait for min_silence_duration_ms before separating it
- Type:
int
- window_size_samples
Audio chunks of window_size_samples size are fed to the silero VAD model. WARNING! Silero VAD models were trained using 512, 1024, 1536 samples for 16000 sample rate. Values other than these may affect model performance!!
- Type:
int
- speech_pad_ms
Final speech chunks are padded by speech_pad_ms each side
- Type:
int
- max_speech_duration_s: float
Alias for field number 2
- min_silence_duration_ms: int
Alias for field number 3
- min_speech_duration_ms: int
Alias for field number 1
- speech_pad_ms: int
Alias for field number 5
- threshold: float
Alias for field number 0
- window_size_samples: int
Alias for field number 4