Asterisk News Reports

I thought it would be nice for my Asterisk server to be able to read me the news, considering as such that it already
tells me the time and the weather. :D A good source of news updates is CNN's podcast, but it needs a little work to make it
Asterisk ready and for it to update automatically on demand. So here's what I did:


Download a copy of Podget (I used version-0.4)
It's available from the following URL, or search for it on sourceforge:

Untar the tarball:

tar -zxvf podget-0.4.tar.gz

and edit the file

cd podget-0.4


Make sure you have everything it shows that it depends on with the exception of "btcursesdownload". Also make sure you have the program "sox" installed as well. Most modern distro's will have these programs standard, but it never hurts to check.

In this shell script, change the variables to the following values:



and comment out these two variables:



Next, is the server list:


# (some commented text) cnn news


Inbetween the top tag and the bottom tag, is the list of servers you will be podcatching from. Initally, theres a couple
of other URL's already in there, you'll probably want to remove those first. In this example, I'm pulling from CNN's RSS
news feed. The two words at the end of the URL are the subdirectories that will be created to hold the new audio files.
You can change them to whatever you want, but make sure you keep them congruent in the rest of the scripts.

Next, change:


Also, probably most importantly, change most_recent=0 to most_recent=1

Write your changes and exit your editor.

Next, make a shell script called "makenews":
(if you changed the directories above, make the changes here too)

for i in /tmp/cnn/news/*.mp3; do nice -n15 sox $i -r 8000 -c 1 /tmp/news.gsm resample -ql; done
rm /tmp/cnn/news/*.mp3

<If you have more than one feed, just repeat this string and change the subfolders>

I've noticed SOX (the converter) is very CPU intensive, so the command 'nice -n15' is added to make it more system friendly.
If this is not a concern, you can lower the "15" closer to "0", or remove 'nice -n15' completely.

and write the file.

Now we have to put the files in place so Asterisk can use them....

Make sure your scripts are executable and owned by the user that asterisk runs as (yours may vary):
(I renamed to just "podget" at this point to match all my other scripts in the directory)

mv podget 
chmod 755 podget
chmod 755 makenews
chown asterisk:asterisk podget
chown asterisk:asterisk makenews

#and move the files to wherever you call your sripts from:
#(for me this is /usr/share/asterisk)

mv podget makenews /usr/share/asterisk

Lastly, add this to your extensions.conf:

exten => *66,1,Answer
exten => *66,n,Playback(privacy-please-stay-on-line-to-be-connected)
exten => *66,n,System(/usr/share/asterisk/podget)
exten => *66,n,System(/usr/share/asterisk/makenews)
exten => *66,n,Playback(/tmp/news)
exten => *66,n,Hangup

Note: You may want to replace Playback with ControlPlayback so that you can move through the sound file

Note: If you have Asterisk 1.09 or older, replace the 'n's with sequential numbers.

Now reload Asterisk, and dial the extension you set for this to work on. The first time it runs, it will take a while to
download and convert the sound file, so be patient. After that, as long as there arent any updates available, it should
be pretty quick. If the first time delay is too long for your liking, and your system can encode the file faster that it can play it back — you can reduce
startup time significantly by making a small change to the dialplan above:

exten => *66,n,System(/usr/share/asterisk/makenews & )
exten => *66,n,Wait(4)
exten => *66,n,Playback(/tmp/news)

You may need to raise the Wait timer in order to give it enough of a head start so you dont run out of data while it's playing. Just make sure if you substitute Playback for ControlPlayback, that you dont fast forward past the end of the file.

Alternatively, you could cron job the 'podget' and 'makenews' scripts to run whenver you want them to, so they're instantly
available. But if no one will dial this extension for a couple days (depends on your traffic), it's pointless to use CPU
and bandwidth to get updates that wont get listened to.

If you want to change the list of feeds (to add or remove some) — make sure you delete the "/tmp/.podget" (rm -rf /tmp/.podget) so that next time the script runs, it will regenerate a new server list.

One last gotcha: The news updates are typically right at 2 minutes long. If you want to play something that's considerably longer, make
sure that your RTP timeout (if you have it set) is long enough to cover the span of your sound file, elsewise it will get
cut off.

Created by: smenten, Last modification: Thu 04 of Nov, 2010 (07:05 UTC) by admin
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+