Say Duration Of Alaw File?
I can get the size of a ulaw file using STAT. And I can get the duration in seconds by doing filesize/8000.
Your tea-break challenge is to help me find the shortest most Asterisk-like way of saying:
“The following file is [ seconds long”.
…without referring to external applications!
Yes, I’m aware of the math behind it, but I was hoping for a nice way than a load of MATH and GoToIf statements 🙂
Thanks
3 thoughts on - Say Duration Of Alaw File?
Alright… How about:
exten => 100,1,NoOP()
same =>
n,Set(Duration=$[CEIL(${STAT(s,/var/lib/asterisk/moh/reno_project-system.alaw)}
/ 8000)])
same => n,NoOP(Duration is $[FLOOR(${Duration} / 60)] Minutes,
$[REMAINDER(${Duration},60)] Seconds)
same => n,Hangup()
Thanks – that got me on the right track. Here’s a context I made to test things out – have a play!
If anyone can think of a more compact way of doing it, I’d be grateful, but this seems to work for now.
Thanks again, John.
exten => 9,1,Answer()
same => n,Set(minSpeech=minutes&and)
same => n,set(playFile=/var/lib/asterisk/sounds/en/abandon-all-hope)
same => n,Gosub(setup)
same => n,set(playFile=/var/lib/asterisk/moh/reno_project-system)
same => n,Gosub(setup)
same => n,Hangup(); tidy up
same => n(setup),Set(totalTime=$[CEIL(${STAT(s,${playFile}.alaw)} / 8000)])
same => n(play),ControlPlayback(${playFile},0,3,1,045679#*,,2,o(${CPLAYBACKOFFSET}))
same => n,Verbose(1,${CPLAYBACKSTATUS})
same => n,GosubIf($[“${CPLAYBACKSTATUS}”=”USERSTOPPED”]?pause)
same => n,Verbose(1,${CPLAYBACKSTATUS})
same => n,GoToIf($[“${CPLAYBACKSTATUS}”=”SUCCESS”]?done:play)
same => n(pause),Verbose(1,Paused)
same => n,Set(totalMin=$[FLOOR(${totalTime} / 60)])
same => n,Set(totalSec=$[REMAINDER(${totalTime},60)])
same => n,Set(pauseTime=$[{CEIL(${CPLAYBACKOFFSET})} / 1000])
same => n,Set(pauseTime=${MATH(${pauseTime}+0,i)})
same => n,Set(pauseMin=$[FLOOR(${pauseTime} / 60)])
same => n,Set(pauseSec=$[REMAINDER(${pauseTime},60)])
same => n,Verbose(1,Paused at ${pauseMin} minute and ${pauseSec}
into ${totalMin} ${totalSec} file)
same => n,Set(fullSpeech=dictate/paused&digits/at${pauseMinSpeech}${pauseSecSpeech}&vm-duration${totalMinSpeech}${totalSecSpeech})
same => n,Background(dictate/paused&digits/at)
same => n,Verbose(1,${totalMin},${totalSec},${pauseMin},${pauseSec})
same => n,GotoIf($[${pauseTime} > 59 ]?pauseMin:pauseSec)
same => n(pauseMin),SayNumber(${pauseMin})
same => n,Background(${minSpeech})
same => n(pauseSec),SayNumber(${pauseSec})
same => n,Background(seconds)
same => n,Background(vm-duration)
same => n,GotoIf($[${totalTime} > 59 ]?totalMin:totalSec)
same => n(totalMin),SayNumber(${totalMin})
same => n,Background(${minSpeech})
same => n(totalSec),SayNumber(${totalSec})
same => n,Background(seconds)
same => n,Return() ; continue where we left
same => n(done),Set(CPLAYBACKOFFSET=0)
same => n,Return()
This is the most compact I can make it just by tidying up your variables and playbacks:
same =>
n,Set(ARRAY(minSpeech,playFile)=minutes&and,/var/lib/asterisk/sounds/en/abandon-all-hope)
same => n,Gosub(setup)
same => n,set(playFile=/tmp/reno_project-system)
same => n,Gosub(setup)
same => n,Hangup(); tidy up
same => n(setup),Set(totalTime=$[CEIL(${STAT(s,${playFile}.alaw)} /
8000)])
same =>
n(play),ControlPlayback(${playFile},0,3,1,045679#*,,2,o(${CPLAYBACKOFFSET}))
same => n,GosubIf($[“${CPLAYBACKSTATUS}”=”USERSTOPPED”]?pause)
same => n,GoToIf($[“${CPLAYBACKSTATUS}”=”SUCCESS”]?done:play)
same =>
n(pause),Set(ARRAY(totalMin,totalSec,pauseTime)=$[FLOOR(${totalTime} /
60)],$[REMAINDER(${totalTime},60)],$[{CEIL(${CPLAYBACKOFFSET})} / 1000])
same => n,Set(pauseTime=${MATH(${pauseTime}+0,i)})
same => n,Set(ARRAY(pauseMin,pauseSec)=$[FLOOR(${pauseTime} /
60)],$[REMAINDER(${pauseTime},60)])
same => n,Playback(dictate/paused&digits/at)
same => n,ExecIF($[${pauseTime} > 59
]?Playback(digits/${pauseMin}&${minSpeech}))
same => n,SayNumber(${pauseSec})
same => n,Playback(seconds&vm-duration)
same => n,ExecIF($[${totalTime} > 59
]?Playback(digits/${totalMin}&${minSpeech}))
same => n,SayNumber(${totalSec})
same => n,Playback(seconds)
same => n,Return() ; continue where we left
same => n(done),Set(CPLAYBACKOFFSET=0)
same => n,Return()