Wednesday, September 1, 2010

ARRL News on Allstar Node

After some review, and testing. I have updated my previous script to download the Amateur Radio Newsline when the ARRL Audio news is unavailable. I also made the script choose which announcement to play, based on which news was downloaded.

My scripts are available to Amateur Radio Operator to use. I only ask that you make a comment here and let me know where it is deployed.

To use this script, you will need to create a "news" directory first by entering "mkdir /var/lib/asterisk/sounds/rpt/news".

You will also need to create 2 audio files for this. These are your precursor announcements, and I include the command to stop automated playback in the announcement, just in case there is emergency or priority traffic.

/var/lib/asterisk/sounds/rpt/ARRL-QST-News.ulaw
/var/lib/asterisk/sounds/rpt/ARN-QST-News.ulaw

Here is an example script that I read, and recorded into a ulaw format for the node per support instructions, (http://ohnosec.org/drupal/node/142):
------------------
QST QST QST

Please stand by for a re-transmission of last weeks ARRL Audio News.

When available, the ARRL Audio News is re-transmitted on this WA6YBN Repeater every Monday night at 7 PM Local Time. If the ARRL Audio News is unavailable, the Amateur Radio Newsline will be aired in its place.

If you have Emergency or Priority traffic during an automated playback, use *999 to cancel it.

For more information, e-mail WA6YBN@GMAIL.COM or visit us at qsl.net/wa6ybn

The Re-Transmission of the ARRL Audio News will begin momentarily.
------------------

Next, create the script file, watch out for word wrap if you copy and paste from this site. I will post the script file somewhere and post a link here for download.

Enter "vi /etc/asterisk/news", then type "i" to begin editing. Copy and paste the script below.
-------------------------------------------------------------------------------------


#!/bin/bash
#Please comment on my blog as to where this script is running. Thanks
#Script by KI6PSP, Ref KI6PSP.BLOGSPOT.COM, 73s
cd /var/lib/asterisk/sounds/rpt/news/
#Cleanup last weeks news file
rm -f /var/lib/asterisk/sounds/rpt/news/QST-News.ulaw
rm -f /var/lib/asterisk/sounds/rpt/news/news.wav
rm -f /var/lib/asterisk/sounds/rpt/news/news.mp3
rm -f /var/lib/asterisk/sounds/rpt/news/news.gsm
echo "Starting Dowload of ARRL Audio News @ $(date +%H:%M:%S)"
wget http://www.arrl.org/files/file/News/Audio%20News/AudioNews$(date --date="last thursday" +%m%d%y).mp3
if [ -f /var/lib/asterisk/sounds/rpt/news/AudioNews$(date --date="last thursday" +%m%d%y).mp3 ];
 then
 echo "Download complete @ $(date +%H:%M:%S)"
 #Extract the MP3 to RAW
 #Long Command here, may wordwrap......
 /usr/local/bin/mpg123 -s --rate 44100 --mono /var/lib/asterisk/sounds/rpt/news/AudioNews$(date --date="last thursday" +%m%d%y).mp3 > /var/lib/asterisk/sounds/rpt/news/news1.raw
 #Verify Extraction Completed
  if [ -f /var/lib/asterisk/sounds/rpt/news/news1.raw ]
  then
  echo "MP3 Expansion Complete, Starting Conversion @ $(date +%H:%M:%S)"
  #Convert RAW to WAV and reduce volume
   #Change the "-v .8" to a value acceptable for your system, .8 means 80% of original volume.
  /usr/bin/sox -r 44100 -w -s -c 1 /var/lib/asterisk/sounds/rpt/news/news1.raw -r 8000 -v .8 -c 1 /var/lib/asterisk/sounds/rpt/news/news.wav
  #Verify Conversion Completed
     if [ -f /var/lib/asterisk/sounds/rpt/news/news.wav ];
     then
     echo "Download and Conversion Completed @ $(date +%H:%M:%S)"
     else
     echo "Conversion Failed @ $(date +%H:%M:%S)"
     exit
     fi
  else
  echo "MP3 Expansion Failed @ $(date +%H%M%S)"
  exit
  fi
 #Cleanup MP3 Download and RAW File
 rm -f /var/lib/asterisk/sounds/rpt/news/AudioNews$(date --date="last thursday" +%m%d%y).mp3
 rm -f /var/lib/asterisk/sounds/rpt/news/news1.raw
 #List directory for log file
 cp /var/lib/asterisk/sounds/rpt/ARRL-QST-News.ulaw /var/lib/asterisk/sounds/rpt/news/QST-News.ulaw
 ls -l
 else
 echo "ARRL Audio News Unavailable, Downloading Amateur Radio Newsline @ $(date +%H:%M:%S)"
 rm -f /var/lib/asterisk/sounds/rpt/news/missing.png
 wget http://arnewsline.squarespace.com/storage/audio/news.mp3
   if [ -f /var/lib/asterisk/sounds/rpt/news/news.mp3 ];
   then
   echo "Download complete @ $(date +%H:%M:%S)"
   /usr/local/bin/mpg123 -s --rate 44100 --mono /var/lib/asterisk/sounds/rpt/news/news.mp3 > /var/lib/asterisk/sounds/rpt/news/news1.raw
     if [ -f /var/lib/asterisk/sounds/rpt/news/news1.raw ]
     then
     echo "MP3 Expansion Complete, Starting Conversion @ $(date +%H:%M:%S)"
     #Convert RAW to WAV and reduce volume
      #Change the "-v .8" to a value acceptable for your system, .8 means 80% of original volume.
     /usr/bin/sox -r 44100 -w -s -c 1 /var/lib/asterisk/sounds/rpt/news/news1.raw -r 8000 -v .8 -c 1 /var/lib/asterisk/sounds/rpt/news/news.wav
     #Verify Conversion Completed
       if [ -f /var/lib/asterisk/sounds/rpt/news/news.wav ];
       then
       echo "Download and Conversion Completed @ $(date +%H:%M:%S)"
       #Cleanup MP3 Download and RAW File
       rm -f /var/lib/asterisk/sounds/rpt/news/news.mp3
       rm -f /var/lib/asterisk/sounds/rpt/news/news1.raw
       #List directory for log file
       cp /var/lib/asterisk/sounds/rpt/ARN-QST-News.ulaw /var/lib/asterisk/sounds/rpt/news/QST-News.ulaw
       ls -l
       else
       echo "Conversion Failed @ $(date +%H:%M:%S)"
       exit
       fi
     else
     echo "MP3 Expansion Failed @ $(date +%H%M%S)"
     #If download failed, delete the retrieved PNG File and copy alternate file to news.wav
     cp /var/lib/asterisk/sounds/rpt/NONE-QST-News.ulaw /var/lib/asterisk/sounds/rpt/news/news.ulaw
     exit
     fi
   else
   #If download failed, delete the retrieved PNG File and copy alternate file to news.wav
   cp /var/lib/asterisk/sounds/rpt/news/memory_notfound.gsm /var/lib/asterisk/sounds/rpt/news/news.gsm
   cp /var/lib/asterisk/sounds/rpt/NONE-QST-News.ulaw /var/lib/asterisk/sounds/rpt/news/QST-News.ulaw
   fi
 exit
 fi
exit

-------------------------------------------------------------------------------------

After pasting this, you need to save it by hitting the "Esc" key, then typing ":wq". Next we need to make sure the script has permission to run, by entering "sudo chmod o+x /etc/asterisk/news"

I created this script because I needed to download the MP3, but I convert the file because I couldn't get the MP3Player to work in Asterisk. I had everything installed, but couldn't get the syntax to actually play the file. But I was already playing wav files.

*****You will need to install the Add-on for Asterisk using these commands:*****

cd /tmp/
wget http://downloads.asterisk.org/pub/telephony/asterisk/old-releases/asterisk-addons-1.4.13.tar.gz
tar -xf asterisk-addons-1.4.13.tar.gz
cd asterisk-addons-1.4.13
make clean
./configure
make install
service asterisk restart

Now your reasy to test, to run the script manually for testing purposes, enter "/etc/asterisk/news"

To automate this script, I used crontab. I typed "crontab -e" and pasted in the following:
0 7 * * 5 /etc/asterisk/news > /etc/asterisk/news.log
This will run my script on Friday Mornings, so the news will be ready to go for Monday nights.

To make this fully automated, we modify the rpt.conf to add something like this:

[schedule27178]
25= 0 19 * * 1     ;Announce the News Re-Transmission at 7:00 PM on Monday
26= 1 19 * * 1     ;Begin playback of the ARRL Audio news that is already downloaded

[functions27178]
925=playback,rpt/QST-News     ;Command to make Announcement
926=playback,rpt/news/news     ;Command to start playback
999=cop,24 ; Flush All Telemetry (AKA:Be Quiet)

[macro27178]
25=*925#     ;Macro for scheduler to make Announcement
26=*926#     ;Macro for scheduler to start playback

This repeater is setup to Morse its ID over the audio, so I don't have to key in the Club Call during the news.

Ed
KI6PSP
http://ki6psp.blogspot.com/