用Raspberry Pi听BBC

    Raspberry Pi是基于ARM架构的卡片电脑,其小巧(信用卡大小),低功耗(手机充电器就可以给其供电),无噪音(无风扇)的特点吸引了我。我给它安装了基于debian的rasbian linux系统。由于其低功耗和无噪音的特性,可以24小时不间断运行。最近正好在海外出差,为了提高蹩脚的英语听力决定用我的Pi制作BBC网络收音机。

wKioL1OlyOiju3SNACV8MjyjjnU478.jpg

思路:

    Linux+Mplayer


Rasbian是基于Debian的Linux系统,所以大部分命令行软件都可以使用。


先安装Mplayer

pi@raspberrypi:~$ sudo apt-get install mplayer


给Raspberry Pi安装声音服务

sudo apt-get install alsa-utils

加载驱动

sudo modprobe snd_bcm2835

编译DEMO

cd /opt/vc/src/hello_pi/
./rebuild.sh

测试DEMO

cd hello_audio

3.5毫米输出

./hello_audio.bin


用mplayer播放网络流媒体(BBC)

pi@raspberrypi:~$ mplayer -loop 0 -cache 1024 -af volume=-10 mms://livewmstream-ws.bbc.co.uk.edgestreams.net/reflector:38972 < /dev/null > /dev/null 2>1&

其中volume值是调整音量

-cache 1024 是为了缓存,如果网络特别好的话这个就不用了。但是执行命令行后需要等待一段时间缓存后才能听到收音机。


上面这个命令每次都输入的话非常繁琐,所以我做成了shell脚本,保存为文件名bbc1

pi@raspberrypi:~$ cat bbc1
#!/bin/sh
sudo kill -s 9 `ps -aux | grep mplayer | awk '{print $2}'`
mplayer -loop 0 -cache 1024 -af volume=-10 mms://livewmstream-ws.bbc.co.uk.edgestreams.net/reflector:38972 < /dev/null > /dev/null 2>1&


这样可以通过以下命令来执行

pi@raspberrypi:~$ sh ./bbc1


如果想要让每次Pi启动的时候自动播放BBC则可以修改/etc/rc.local文件

在exit 0上面一行

pi@raspberrypi:~$ sudo vi /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi
sh /home/pi/bbc1

exit 0


保存后以后每次启动Raspberry Pi,只要有网络的话都可以自动播放BBC的。

如果对Raspberry Pi自带的3.5mm音频输出口的音质不满意的话可以从网上淘一个 USB DAC,音质提升很明显。这个下期再讨论。

下期预告:Raspberry Pi变成无损HiFi音乐播放器

你可能感兴趣的:(树莓派,raspberry,网络收音机)