#!/usr/bin/env python3 import subprocess, math, array SRC="filename.flac" OUT="silence-filename.flac" SR=96000 CHUNK=0.1 STEP=int(SR*CHUNK) THRESH=-32 SIL=bytearray() pcm=subprocess.check_output([ "ffmpeg","-i",SRC,"-vn","-f","f32le","-ac","1","-ar",str(SR),"-" ],stderr=subprocess.DEVNULL) a=array.array('f'); a.frombytes(pcm) N=len(a) for i in range(0, N, STEP): seg=a[i:i+STEP] if not seg: break rms=math.sqrt(math.fsum(x*x for x in seg)/len(seg)) peak=max(abs(x) for x in seg) db_r=20*math.log10(rms) if rms>0 else -1000 db_p=20*math.log10(peak) if peak>0 else -1000 if db_r