[asterisk-users] using Playback() to play a random sound file
dave cantera
david.cantera at iacnet.net
Sat May 5 19:07:29 MST 2007
steve,
thats Great... my C is old and ftw operated differently on sysV,
solaris, sunos, ultrix, and osf... so I went back to bourne...
couldn't work through the idiosyncracies of gnu autoconf, etc...
although I have a many reasons to, I just couldn't get to production 'C'
coding level...
daveC
Steve Edwards wrote:
>>> Steve Edwards wrote:
>>> On Tue, 1 May 2007, Jay Austad wrote:
>>>
>>>> I've got a directory under /var/lib/asterisk/sounds which contains
>>>> a bunch
>>>> of sound files. I would like to call the Playback command to play the
>>>> files, but I need it to select a file to play randomly. Is there
>>>> any way
>>>> to do this?
>>>
>>> I do this with an AGI.
>
> On Wed, 2 May 2007, dave cantera wrote:
>
>> here is a way that I solved a similar problem... have a shell script
>> that
>> runs and indexes all the files in the directory into an ascii flat
>> file with
>> a format of
>> #### filename
>> 0001 directory/tt-weasels
>> 0002 directory/tt-monkeys
>>
>> in your dialplan use the rand() to pick a number, pass it to the
>> shell script
>> as an arg[], then the shells script grep()'s and cut()'s the filename
>> puts it
>> in a db varaible, the dialplan picks it up and plays it... as you
>> can see, I
>> haven't done it yet :) but, in theory it works... you could skip the
>> dialplan rand() and just use linux rand based on the minutes or
>> seconds value
>> for current time...
>>
>> you don't have to zero fill the index either, I seem to like nicely
>> formated
>> files, they are easier for humans to read.
>> daveC
>
> Sounds like a lot of effort to avoid writing an AGI. If you have the
> skills to write the script described above, you have the skills to
> write an AGI -- you can write AGI's in shell scripts, btw.
>
> AGI's accept stuff from Asterisk on stdin and send stuff back to
> Asterisk on stdout -- very simple and elegant actually. Take your
> script and rewrite the "reading arguments" bits to read from stdin and
> change the "write db" bits to write to stdout (set a channel variable)
> and you have an AGI and a much cleaner dialplan.
>
> I write AGI's in C for speed and flexibility. No interpreter (bash,
> perl, php, etc.) to fire up, full access to anything you want to do.
>
> In C, I call ftw() ("ftw - traverse (walk) a file tree"). If I get
> more than 1 file, I choose one randomly.
>
> Thanks in advance,
> ------------------------------------------------------------------------
> Steve Edwards sedwards at sedwards.com Voice: +1-760-468-3867 PST
> Newline Fax: +1-760-731-3000
> _______________________________________________
> --Bandwidth and Colocation provided by Easynews.com --
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
> http://lists.digium.com/mailman/listinfo/asterisk-users
>
>
>
--
Building Strong Relationships w/ Intelligent Customer Service
--
Interlocking Business Solutions, LLC
856-380-0894 x5000
More information about the asterisk-users
mailing list