Note
Go to the end to download the full example code.
Trim silence and find active regions
trim_db removes leading and trailing quiet, split_db lists the sounding
intervals, and speech_regions runs voice activity detection.
import numpy as np
import audio_samples as aus
from audio_samples import mpl
Two bursts of a tone with silence around and between them.
sr = 16000
tone = aus.generation.sine_wave(300.0, 0.5, sr, amplitude=0.5).as_f32()
gap = aus.generation.silence(0.5, sr).as_f32()
audio = aus.AudioSamples.concatenate([gap, tone, gap, tone, gap])
kept samples 7168 to 33280 of 40000
[[0.448 1.088]
[1.44 2.08 ]]

[(8192, 19456), (24064, 35328)]
Total running time of the script: (0 minutes 0.074 seconds)