Having fun with audio!?!

Like to use my server as a stereo so to speak. Either can play sound files directly or can play music from the internet! For some reason the sound was not working on my system, so I decided to remove the pulse stuff and reinstall the alsa setup. This is the only method that I have found that works flawlessly:

$ sudo killall pulseaudio
$ sudo apt-get purge pulseaudio pulseaudio-utils gstreamer0.10-pulseaudio \
 libpulse-browse0 paman pavumeter pavucontrol 
$ sudo apt-get purge 
$ sudo mv /etc/asound.conf /etc/asound.conf-bak
$ rm ~/.pulse-cookie
$ rm -r ~/.pulse

Reboot. Then install:
 
$ sudo apt-get install alsa-base alsa-tools alsa-tools-gui alsa-utils alsa-oss \
 alsamixergui libalsaplayer0 
 
Everything now works fine! In fact, sound is better than it ever has been. 
Speakers seem to gently boom out the sound. Now you will want to install mplayer. 
Most everyone knows how to use mplayer, if not use
 
$ sudo apt-get install mplayer
$ man mplayer
 
That should do well enough. Anyway, what I wanted to do was to have an internet radio 
that I could access from the command line. It is not really hard to do with mplayer.
The hard part is getting the url with the playlist as part of the url. The reason for
that is not to have to store the playlist file locally. That saves space and you
will always have the latest version. You will have to save links to see which ones
works. Since I will be accessing the server remotely, I plan to use the command line
so that I do not have to deal with the monitor on the server. It can stay off!
 
 
 
 
When you deal with anything command line, you are talking about using a batch file
unless you want to manually always type in the commands. You can go to 
http://radio-locator.com/ a list of stations. Let's go for the menu method for 
choosing what internet radio stations to listen to such as this:
 
 
Since made some changes, but that is ok. Found a better radio station or two. Like I said
you can enter the commands one at a time for instance if you have a complete url with the
playlist, you might use:
 
$  mplayer -playlist  http://www.publicbroadcasting.net/kuhf/ppr/kuha_128.m3u
 
Not all internet radio stations will let you do that, so you have to download the 
playlist locally. They you might use:
 
$ mplayer -playlist koda-fm.m3u
 
That assuming the playlist is in the current directory, otherwise you will have to use
the correct path to the file. Since I do not have a lot of radio stations to listen to,
setting up a simple batch files with all the information to use the playlists is easy. So
here is some example code that could be used on a server or even an embedded device 
such as the Raspberry Pi:  
 
#!/bin/bash
#
# Script to emulate a radio.
#
while :
do
clear
echo "************************"
echo "* Radio tuner          *"
echo "************************"
echo "* [1] Alvin            *"
echo "* [2] 91.7 classical   *"
echo "* [3] 88.7 global      *"
echo "* [4] Kuhf news        *"
echo "* [5] KPFT             *"
echo "* [6] Koda             *"
echo "* [7] KTBZ             *"
echo "* [8] KSBJ             *"
echo "* [9] Klol             *"
echo "*                      *"
echo "* [0] Exit/Stop        *"
echo "************************"
echo
echo "Enter your menu choice [1-9 or 0]: "
read -n 1 yourch
case $yourch in
1) mplayer -playlist http://www.kaccradio.com/images/KACCRadio.asx  ;;
2) mplayer -playlist  http://www.publicbroadcasting.net/kuhf/ppr/kuha_128.m3u  ;;
3) mplayer -playlist  http://www.publicbroadcasting.net/kuhf/ppr/kuhfglobal_128.m3u  ;;
4) mplayer -playlist http://www.publicbroadcasting.net/kuhf/ppr/kuhfnews_128.m3u  ;;
5) mplayer -playlist http://kpft.org/KPFT-hifi.wma ;; 
6) mplayer -playlist [path]/koda-fm.m3u  ;;
7) mplayer -playlist [path]/ktbz-fm.m3u  ;;
8) mplayer -playlist [path]/ksbjfmaac.pls  ;;
9) mplayer -playlist [path]/klolfmaac.pls ;;
0) exit 0;;
*) echo "Oopps!!! Please select choice 1,2,3,4,5,6,7,8, or 9"
echo "Press Enter to continue. . ." ; read ;;
esac
done


You could reuse this script for other projects 
#!/bin/bash
#
# Script to [description].
#
while :
do
clear
echo "************************"
echo "*  [Title]             *"
echo "************************"
echo "* [1]                  *"
echo "* [2]                  *"
echo "* [3]                  *"
echo "* [4]                  *"
echo "* [5]                  *"
echo "* [6]                  *"
echo "* [7]                  *"
echo "* [8]                  *"
echo "* [9]                  *"
echo "*                      *"
echo "* [0] Exit/Stop        *"
echo "************************"
echo
echo "Enter your menu choice [1-9 or 0]: "
read -n 1 yourch
case $yourch in
1)   ;;
2)   ;;
3)   ;;
4)   ;;
5)   ;; 
6)   ;;
7)   ;;
8)   ;;
9)   ;;
0) exit 0;;
*) echo "Oopps!!! Please select choice 1,2,3,4,5,6,7,8, or 9"
echo "Press Enter to continue. . ." ; read ;;
esac
done

------------------------------------------------------------------------ 
Under construction: 
 
So there is the barebones script to play music on the local server speakers. Have fun! You 
certainly can use a web based menu, so you do not have to log into the machine, but that is 
for another day. Be sure to add the web user to the audio group. But this might wet your 
appetite for use as a web page on a server. We will be using the slave mode to finish this 
script up.  More later.
 
 
 
#!/bin/sh
 echo "Content-type: text/html\n"
  
 # read in our parameters
 CMD=`echo "$QUERY_STRING" | sed -n 's/^.*cmd=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`

 # our html header
 echo "<html>"
 echo "<head><title>Internet radio</title></head>"
 echo "<body>"
  
 # test if any parameters were passed
 if [ $CMD ]
 then
   case "$CMD" in
1) 
 echo "mplayer KACCRadio :<pre>"
  /usr/bin/mplayer -playlist http://www.kaccradio.com/images/KACCRadio.asx  
 echo "</pre>"
   ;;
2) 
 echo "player kuhf :<pre>"
 /usr/bin/mplayer -playlist  http://www.publicbroadcasting.net/kuhf/ppr/kuha_128.m3u  
 echo "</pre>"
   ;;
3) 
 echo "mplayer kuhfglobal :<pre>"
 /usr/bin/mplayer -playlist  http://www.publicbroadcasting.net/kuhf/ppr/kuhfglobal_128.m3u  
 echo "</pre>"
   ;;
4) 
 echo "mplayer kuhfnews
 :<pre>"
 /usr/bin/mplayer -playlist http://www.publicbroadcasting.net/kuhf/ppr/kuhfnews_128.m3u  
 echo "</pre>"
  ;;
5) 
 echo "mplayer kpft :<pre>"
 /usr/bin/mplayer -playlist http://kpft.org/KPFT-hifi.wma 
 echo "</pre>"
   ;;
6)
 echo "mplayer koda :<pre>" 
   /usr/bin/mplayer -playlist koda-fm.m3u  
 echo "</pre>" 
  ;;
7) 
   echo "mplayer ktbz :<pre>" 
 /usr/bin/mplayer -playlist ktbz-fm.m3u  
 echo "</pre>"
   ;;
8) 
 echo "mplayer ksbj :<pre>" 
   /usr/bin/mplayer -playlist ksbjfmaac.pls  
 echo "</pre>" 
  ;;
9) 
 echo "mplayer klol :<pre>" 
   /usr/bin/mplayer -playlist klolfmaac.pls 
 echo "</pre>"
 ;;
                 
      *)
       echo "Unknown command $CMD<br>"
       ;;
   esac
 fi
  
 # print out the form
  
 # page header
 echo "<p>"
 echo "<center>"
 echo "<h2>Radio stations</h2>"
 echo "</center>"
 echo "<p>"
 echo "<p>"
  
 echo "Choose which radio station do you want to listen to: "
 echo "<form method=get>"
 echo "<input type=radio name=cmd value=1> Alvin <br>"
 echo "<input type=radio name=cmd value=2> 91.7 classical <br>"
 echo "<input type=radio name=cmd value=3> 88.7 global <br>"
 echo "<input type=radio name=cmd value=4> Kuhf news <br>"
 echo "<input type=radio name=cmd value=5> KPFT <br>"
 echo "<input type=radio name=cmd value=6> Koda <br>"
 echo "<input type=radio name=cmd value=7> KTBZ <br>"
 echo "<input type=radio name=cmd value=8> KSBJ <br>"
 echo "<input type=radio name=cmd value=9> Klol <br>"
 echo "<input type=submit>"
 echo "</form>"
 echo "</body>"
 echo "</html>"


Try at your own risk.


Comments

Popular posts from this blog

Guiless?

Web.com and Network Solutions, the Walmart of the internet.

MSOffice vs Libreoffice