0

I currently have some python code that constantly records 4-second chunks of audio:

#!/usr/bin/env python3
import sounddevice as sd

fs = 16000

while True:
    print('Started listening')
    myrecording = sd.rec(int(4 * fs), dtype='int16', channels=1, blocking=True)

However, instead of having a fixed 4-second chunk, I would like sounddevice to record until the volume of the drops below a threshold of audio (ie, when the person with the microphone has stopped talking), and then start listening again.

Essentially, I want to mimic the behaviour of a command like sox's rec recording.wav silence 1 0.1 3% 1 3.0 3%, which does exactly this.

Is there an easy way to do this with sounddevice?

Migwell
  • 18,631
  • 21
  • 91
  • 160
  • The `sounddevice` module cannot help you with the signal analysis, its job is just providing the signal. But you can write your own hand-written callback function that does the analysis and use that in a `sounddevice.InputStream`. – Matthias Dec 10 '18 at 19:42

1 Answers1

1

It seems that the libraries that do this are called VAD (voice audio detection). For python, a good one seems to be py-webrtcvad.

Migwell
  • 18,631
  • 21
  • 91
  • 160