└── BluetoothSpeaker.md /BluetoothSpeaker.md: -------------------------------------------------------------------------------- 1 | ### RaspberryPi 3B Bluetooth Speaker 2 | 3 | #### Required 4 | * RaspberryPi Model 3B 5 | * headset(Speaker) 6 | 7 | #### Install Dependency Packages 8 | 9 | Prepare your RaspberryPi, with RASPBIAN JESSIE LITE(or RASPBIAN JESSIE). 10 | 11 | Assume you are login as root. 12 | 13 | Install the dependency packages: 14 | 15 | apt-get update 16 | apt-get install bluez pulseaudio-module-bluetooth python-gobject python-gobject-2 17 | #### Check And Pair Bluetooth 18 | check cmds: 19 | 20 | bluetoothctl: 21 | scan on 22 | trust xx:xx:xx:xx:xx:xx(your phone bluetooth mac) 23 | connect xx:xx:xx:xx:xx:xx(use pi connect phone first, next time you can connect phone with pi on your phone) 24 | if connected, completed checking of bluetooth 25 | #### Config Bluetooth 26 | we'll config Bluetooth, to enable Bluetooth Audio 27 | cmds: 28 | 29 | vim /etc/bluetooth/main.conf 30 | 31 | Add the following line in the [General] section: 32 | 33 | Enable=Source,Sink,Media 34 | Set Bluetooth Class, Modify the following line to: 35 | 36 | Class = 0x00041C 37 | 38 | 41C means your bluetooth contains audio functions 39 | #### Config Raspberry Pi Audio 40 | 41 | 42 | vim /etc/pulse/daemon.conf 43 | 44 | 45 | Add the following line after the commented example ";resample-method = speex-float-3": 46 | 47 | resample-method = trivial 48 | 49 | start pulseaudio service with: 50 | 51 | pulseaudio -D 52 | lately, you can add this command to the rc.local script to enable Audio on start. 53 | load modules with: 54 | 55 | pactl load-module module-bluetooth-discover 56 | plugin your headset on raspberyPi 57 | test it with: 58 | 59 | apt-get install omxplayer 60 | omxplayer example.mp3 61 | now you should have heard the sound from the headset 62 | ctrl+C, when tests end 63 | #### Connect Bluetooth with Audio 64 | now restart your bluetooth service: 65 | service bluetooth restart 66 | 67 | bluetoothctl: 68 | power on 69 | connect xx:xx:xx:xx:xx:xx 70 | now, you should have see your bluetooth sources with: 71 | 72 | pactl list sources short 73 | some texts like: 74 | 75 | 0 alsa_output.platform-bcm2835_AUD0.0.analog-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz SUSPENDED 76 | 77 | 1 bluez_source.XX_XX_XX_XX_XX_XX module-bluetooth-device.c s16le 2ch 44100Hz SUSPENDED 78 | then show the sinks: 79 | 80 | pactl list sinks short 81 | 82 | 0 alsa_output.platform-bcm2835_AUD0.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED 83 | remember the alsa_output.xxxxxxx, for later uses 84 | Connect the source to the sink: 85 | 86 | pactl load-module module-loopback source=bluez_source.XX_XX_XX_XX_XX_XX sink=alsa_output.xxxxxxx 87 | config raspberryPi use headset output Interface: 88 | 89 | raspi-config: 90 | Advanced Options 91 | Audio 92 | Force 3.5mm ('headphone') jack 93 | now apply the volume settings: 94 | amixer set Master 100% 95 | pacmd set-sink-volume 0 65537 96 | play some music from phone, raspberryPi should have redirected the sound to your headset.Just like you have plugin headset directly in the phone 97 | 98 | 99 | #### End 100 | The key section is the "Config Raspberry Pi Audio" and "Connect Bluetooth with Audio" 101 | When first test, you could start pulseaudio without -D, so you can see any error logs directly 102 | --------------------------------------------------------------------------------