[asterisk-users] Say duration of alaw file?

Jonathan H lardconcepts at gmail.com
Tue Oct 18 17:48:47 CDT 2016


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()

On 18 October 2016 at 17:56, John Kiniston <johnkiniston at gmail.com> wrote:
> 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()
>
>
> On Tue, Oct 18, 2016 at 7:26 AM, Jonathan H <lardconcepts at gmail.com> wrote:
>>
>> 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 [<n> minutes and] <s> 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
>>
>> --
>> _____________________________________________________________________
>> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>>
>> Join the Asterisk Community at the 13th AstriCon, September 27-29, 2016
>>       http://www.asterisk.org/community/astricon-user-conference
>>
>> New to Asterisk? Start here:
>>       https://wiki.asterisk.org/wiki/display/AST/Getting+Started
>>
>> asterisk-users mailing list
>> To UNSUBSCRIBE or update options visit:
>>    http://lists.digium.com/mailman/listinfo/asterisk-users
>
>
>
>
> --
> A human being should be able to change a diaper, plan an invasion, butcher a
> hog, conn a ship, design a building, write a sonnet, balance accounts, build
> a wall, set a bone, comfort the dying, take orders, give orders, cooperate,
> act alone, solve equations, analyze a new problem, pitch manure, program a
> computer, cook a tasty meal, fight efficiently, die gallantly.
> Specialization is for insects.
> ---Heinlein
>
> --
> _____________________________________________________________________
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>
> Join the Asterisk Community at the 13th AstriCon, September 27-29, 2016
>       http://www.asterisk.org/community/astricon-user-conference
>
> New to Asterisk? Start here:
>       https://wiki.asterisk.org/wiki/display/AST/Getting+Started
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
>    http://lists.digium.com/mailman/listinfo/asterisk-users



More information about the asterisk-users mailing list