I got this from other website. This guide is really good and complete for setup Raspberry PI as bluetooth speaker. But I modify something to match with my testing.
Raspbian Wheezy Installation Guide
From a fresh installation of Wheezy (2012-12-16-wheezy-raspbian.img), run the following as the default user pi:
pi@raspberrypi ~ $ sudo apt-get install bluez pulseaudio-module-bluetooth python-gobject python-gobject-2
Add the user pi to the group lp. This is so the user pi can get access to the bluetooth daemon. If this isn’t done, the bluez source will not show up in pulse audio.
pi@raspberrypi ~ $ sudo usermod -a -G lp pi
The bluetooth stack has to be configured for A2DP.
pi@raspberrypi ~ $ sudo nano /etc/bluetooth/audio.conf
Add the following line after [General]:
Change the resampling algorithm for pulse audio(Thanks to +Colin CW!)
pi@raspberrypi ~ $ sudo nano /etc/pulse/daemon.conf
; resample-method = speex-float-3 resample-method = trivial ; ADD THIS LINE
— From this point on, these are the same directions as in the Arch Linux tutorial above —
Reboot at this point!
pi@raspberrypi ~ $ sudo reboot
NOTE: Do not run these with sudo… Run as pi!
Boot up, log-in, and run:
pi@raspberrypi ~ $ bluez-simple-agent
Connect with your smart phone and enter pin / authorize.
After authorization is complete, CTRL-C out.
You can then trust the phone by using the command:
pi@raspberrypi ~ $ bluez-test-device trusted B8:C6:8E:52:E8:CA yes
It shouldn’t ask for a pin in the future…
After the phone is connected, list the sources. A bluez source should show up:
Note: This command will start the PulseAudio daemon in per-user mode if it is not already running!
pi@raspberrypi ~ $ pactl list sources short
0 alsa_output.platform-bcm2835_AUD0.0.analog-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz SUSPENDED 1 bluez_source.B8_C6_8E_52_E8_CA module-bluetooth-device.c s16le 2ch 44100Hz SUSPENDED
List the sinks. An ALSA sink for the BCM codec should show up:
pi@raspberrypi ~ $ pactl list sinks short 0 alsa_output.platform-bcm2835_AUD0.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
Connect the source to the sink: (** Additional from source ** with out this It will not work):
And everytime after you reboot raspberrypi. You have to connect your phone and raspberry first.
pi@raspberrypi ~ $ sudo hciconfig hci0 piscan
pi@raspberrypi ~ $ pactl load-module module-loopback source=bluez_source.B8_C6_8E_52_E8_CA sink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo
If you play the song on the phone, it should be played on the connected speakers. If not, maybe the default output isn’t the line out jack or the volume is muted or too low.
The audio defaults to the HDMI output. I wanted it to play over the headphone jack.
Here is the command to set the source to headphone jack:
pi@raspberrypi ~ $ amixer cset numid=3 1
turn up the ALSA volume:
pi@raspberrypi ~ $ amixer set Master 100%