amsehili / auditok

An audio/acoustic activity detection and audio segmentation tool
MIT License
732 stars 94 forks source link

Extract silence/background noise instead of high energy bursts/speech #27

Closed ma7555 closed 4 years ago

ma7555 commented 4 years ago

Hello, Any simple way to extract the opposite of what the module is doing?

We ae trying to extract both speech AND silence/noise

We could easily extract the speech but any ideas how to extract the silence periods as audio regions as well?

amsehili commented 4 years ago

Hello, Is this helpful ?

ma7555 commented 4 years ago

Yes, it is I have checked it and made a sample that is working. Was only asking if there is a better way?

This is what I have done

from auditok import AudioRegion
from auditok.dataset import one_to_six_arabic_16000_mono_bc_noise
region = AudioRegion.load(one_to_six_arabic_16000_mono_bc_noise)
regions = region.split_and_plot(energy_threshold=65, drop_trailing_silence=True)

# extract pauses
onset = 0
pauses = []
speech = []
for r in regions:
    if onset < r.meta.start:
        pauses.append((onset, r.meta.start))
        onset = r.meta.end
    speech.append(r)

# and the last pause if there exists
if onset < region.duration:
   pauses.append((onset, region.duration))

silence = []
for pause in pauses:
    silence.append(region.seconds[pause[0]:pause[1]])