;使用方法
s := silenceDetect("test.wav",30) ;检测test.wav中响度低于-30db的静音区
;返回数组,单个值包含键值:start开始时间,end结束时间, duration:时长
silenceDetect(file,db := 40){
out_file := A_ScriptDir "\tmp\" GUID() ".wav" ;注意脚本目录下要有tmp文件夹
ret := cmd("""" A_ScriptDir "\tools\ffmpeg64.exe"" -i """ file """ -af silencedetect=n=-" db "dB:d=1 -y """ out_file """","UTF-8")
s := []
l := StrSplit(ret,"`r","`n")
for k,v in l
{
if RegExMatch(v,"\[silencedetect[^\]]*\]\ssilence_start:\s([0-9\.]*)",m)
s.push({"start":floor(m1*1000)})
else if RegExMatch(v,"\[silencedetect[^\]]*\]\ssilence_end:\s([0-9\.]*)\s\|\ssilence_duration:\s([0-9\.]*)",m)
s[s.maxindex()].end := floor(m1*1000), s[s.maxindex()].duration := floor(m2*1000)
}
FileDelete % out_file
return s
}
GUID(){
shellobj := ComObjCreate("Scriptlet.TypeLib")
ret := shellobj.GUID
uuid := RegExReplace(ret,"(\{|\}|-)","")
return uuid
}
info := audioinfo("test.mp3")
msgbox, 64, Notice, % "The File duration is " info.duration "!"
audioinfo(file){
ret := cmd(A_ScriptDir "\tools\ffmpeg64.exe -i """ file """") ;32位请去掉64
if RegExMatch(ret, "Audio:\s*([^\s]+)\s*\(*[^\)]*\)*,\s*(\d+)\s*Hz,\s*([^,]+),\s*([^,]+),\s*([^,]+)\skb/s", match)
{
RegExMatch(ret,"Duration:(\s*[^,]+),",dur)
return {"code":match1,"samRate":match2,"tract":match3,"dep":match4,"bitRate":match5,"duration":dur1}
}
}
time2msc(time){ ;e.g. 01:01:22.342
a := StrSplit(time,".")
b := StrSplit(a.1,":")
f := "0." a.2
return floor(b.1*1000*60*60+b.2*1000*60+b.3*1000+f*1000)
}
msc2time(msc){
return Format("{1:02d}", floor(msc/1000/60/60)) ":" Format("{1:02d}", Mod(floor(msc/1000/60),60)) ":" Format("{1:02d}", Mod(floor(msc/1000),60)) "." Format("{1:03d}", Mod(msc,1000))
}
47 queries in 1.588 seconds |