我目前有一些 python 代码不断记录 4 秒的音频块:
#!/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)
但是,我不想有固定的 4 秒块,而是想sounddevice
记录直到音量降至音频阈值以下(即,当拿着麦克风的人停止说话时),然后再次开始收听。
本质上,我想模仿像sox
's这样的命令的行为rec recording.wav silence 1 0.1 3% 1 3.0 3%
,它就是这样做的。
有没有简单的方法来做到这一点sounddevice
?