当前位置:网站首页>The method of raspberry pie connecting tmall elf speaker to play music through Bluetooth
The method of raspberry pie connecting tmall elf speaker to play music through Bluetooth
2022-07-26 06:59:00 【SimonLiu009】
Use bluealsa Specify a Bluetooth speaker to play through the command line
install bluealsa There are two ways , The first is through apt install , The second is to install through the source code .
1. adopt apt install bluealsa
1.1 Install and start bluealsa service
sudo apt-get install bluealsa
sudo service bluealsa start
1.2 take pi Join the corresponding user group
sudo adduser pi bluetooth
sudo adduser pi audio
1.3 modify /lib/systemd/system/bluetooth.service
sudo nano /lib/systemd/system/bluetooth.service
take ExecStart=/usr/lib/bluetooth/bluetoothd It is amended as follows ExecStart=/usr/lib/bluetooth/bluetoothd --noplugin=sap --plugin=a2dp
File last added ( It seems that it's OK not to add it )
[Install]
WantedBy=bluetooth.target
Alias=dbus-org.bluez.service
1.4 Restart the service
sudo systemctl daemon-reload
sudo systemctl restart bluetooth
1.5 Connect Bluetooth speakers
sudo bluetoothctl
Then type in power on and scan on:
[bluetooth]# power on
Changing power on succeeded
[bluetooth]# scan on
Discovery started
[CHG] Controller xx:xx:xx:xx:5F:11 Discovering: yes
[NEW] Device XX:XX:XX:5A:19:8A xx-xx-xx-5A-19-8A
[NEW] Device XX:XX:XX:84:81:86 xx-xx-xx-84-81-86
[NEW] Device XX:XX:XX:48:0D xx-xx-xx-8A-48-0D
[NEW] Device XX:XX:XX:85:84:9E LYWSD03MMC
[NEW] Device XX:XX:XX:DD:21:84 LYWSD03MMC
[CHG] Device XX:XX:XX:30:CB:5C RSSI: -65
[CHG] Device XX:XX:XX:84:81:86 RSSI: -45
[CHG] Device XX:XX:XX:84:81:86 ManufacturerData Key: 0x004c
[CHG] Device XX:XX:XX:84:81:86 ManufacturerData Value:
xx xx xx 59 75 0d de c3 15 f6 85 e9 c7 .....`Yu........
[CHG] Device XX:XX:XX:DD:21:84 RSSI: -77
[CHG] Device XX:XX:XX:84:81:86 RSSI: -54
[CHG] Device XX:XX:XX:DD:21:84 RSSI: -87
Input devices View device list
[bluetooth]# devices
Device XX:XX:XX:DD:21:84 LYWSD03MMC
Device XX:XX:XX:85:84:9E LYWSD03MMC
Device XX:XX:XX:8A:48:0D xx-xx-xx-8A-48-0D
Device XX:XX:XX:84:81:86 xx-xx-xx-84-81-86
Device XX:XX:XX:5A:19:8A xx-xx-xx-5A-19-8A
Device XX:XX:XX:30:CB:5C Sugar cube (6C:7C)
I want to connect my tmall fairy candy ( In the list Sugar cube (6C:7C),XX:XX:XX:30:CB:5C It is the mac Address ). First connection , need pair and trust(trust After that, it will connect automatically next time ), If your tmall elf is not on the list , Then voice wakes up tmall elf and says “ Turn on Bluetooth ”, And then again scan on once .
pair XX:XX:XX:30:CB:5C
trust XX:XX:XX:30:CB:5C
For the first time pair Manual input may be required yes confirm .
[bluetooth]# pair XX:XX:XX:30:CB:5C
Attempting to pair with XX:XX:XX:30:CB:5C
[CHG] Device XX:XX:XX:30:CB:5C Connected: yes
Request confirmation
[agent] Confirm passkey 529316 (yes/no): yes
[CHG] Device XX:XX:XX:30:CB:5C Modalias: bluetooth:v000Fp1200d1436
[CHG] Device XX:XX:XX:30:CB:5C UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device XX:XX:XX:30:CB:5C UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device XX:XX:XX:30:CB:5C UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device XX:XX:XX:30:CB:5C UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device XX:XX:XX:30:CB:5C UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device XX:XX:XX:30:CB:5C UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device XX:XX:XX:30:CB:5C ServicesResolved: yes
[CHG] Device XX:XX:XX:30:CB:5C Paired: yes
Pairing successful
[CHG] Device XX:XX:XX:30:CB:5C ServicesResolved: no
[CHG] Device XX:XX:XX:30:CB:5C Connected: no
[bluetooth]# trust XX:XX:XX:30:CB:5C
[CHG] Device XX:XX:XX:30:CB:5C Trusted: yes
Changing XX:XX:XX:30:CB:5C trust succeeded
I want to connect my tmall fairy candy , Use connect Command is enough :
connect XX:XX:XX:30:CB:5C
After the connection is successful, the previous prompt will start from [bluetooth] Become the device name ( For this example [ Sugar cube (6C:7C)]):
[bluetooth]# connect XX:XX:XX:30:CB:5C
Attempting to connect to XX:XX:XX:30:CB:5C
[CHG] Device XX:XX:XX:30:CB:5C Connected: yes
Connection successful
[CHG] Device XX:XX:XX:30:CB:5C ServicesResolved: yes
[ Sugar cube (6C:7C)]#
1.6 Play wav Audio
After successful connection exit sign out , You can use aplay The command plays audio through the device :
aplay -D bluealsa:DEV=XX:XX:XX:30:CB:5C,PROFILE=a2dp ./cat1.wav
$ aplay -D bluealsa:DEV=XX:XX:XX:30:CB:5C,PROFILE=a2dp ./cat1.wav
D: ../../../src/asound/bluealsa-pcm.c:1309: Getting BlueALSA PCM: PLAYBACK XX:XX:XX:30:CB:5C a2dp
D: ../../../src/asound/bluealsa-pcm.c:1062: /org/bluealsa/hci0/dev_xx_xx_xx_30_CB_5C/a2dpsrc/sink: Setting constraints
Playing WAVE './cat1.wav' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono
D: ../../../src/asound/bluealsa-pcm.c:532: /org/bluealsa/hci0/dev_xx_xx_xx_30_CB_5C/a2dpsrc/sink: Initializing HW
D: ../../../src/asound/bluealsa-pcm.c:567: /org/bluealsa/hci0/dev_xx_xx_xx_30_CB_5C/a2dpsrc/sink: FIFO buffer size: 1024 frames
D: ../../../src/asound/bluealsa-pcm.c:576: /org/bluealsa/hci0/dev_xx_xx_xx_30_CB_5C/a2dpsrc/sink: Selected HW buffer: 4 periods x 24000 bytes == 96000 bytes
D: ../../../src/asound/bluealsa-pcm.c:600: /org/bluealsa/hci0/dev_xx_xx_xx_30_CB_5C/a2dpsrc/sink: Initializing SW
D: ../../../src/asound/bluealsa-pcm.c:600: /org/bluealsa/hci0/dev_xx_xx_xx_30_CB_5C/a2dpsrc/sink: Initializing SW
D: ../../../src/asound/bluealsa-pcm.c:600: /org/bluealsa/hci0/dev_xx_xx_xx_30_CB_5C/a2dpsrc/sink: Initializing SW
D: ../../../src/asound/bluealsa-pcm.c:600: /org/bluealsa/hci0/dev_xx_xx_xx_30_CB_5C/a2dpsrc/sink: Initializing SW
D: ../../../src/asound/bluealsa-pcm.c:639: /org/bluealsa/hci0/dev_xx_xx_xx_30_CB_5C/a2dpsrc/sink: Prepared
D: ../../../src/asound/bluealsa-pcm.c:600: /org/bluealsa/hci0/dev_xx_xx_xx_30_CB_5C/a2dpsrc/sink: Initializing SW
D: ../../../src/asound/bluealsa-pcm.c:356: /org/bluealsa/hci0/dev_xx_xx_xx_30_CB_5C/a2dpsrc/sink: Starting
D: ../../../src/asound/bluealsa-pcm.c:226: /org/bluealsa/hci0/dev_xx_xx_xx_30_CB_5C/a2dpsrc/sink: Starting IO loop: 8
D: ../../../src/asound/bluealsa-pcm.c:600: /org/bluealsa/hci0/dev_10_9E_3A_30_CB_5C/a2dpsrc/sink: Initializing SW
D: ../../../src/asound/bluealsa-pcm.c:607: /org/bluealsa/hci0/dev_10_9E_3A_30_CB_5C/a2dpsrc/sink: Changing SW avail min: 6000 -> 1
D: ../../../src/asound/bluealsa-pcm.c:600: /org/bluealsa/hci0/dev_10_9E_3A_30_CB_5C/a2dpsrc/sink: Initializing SW
D: ../../../src/asound/bluealsa-pcm.c:607: /org/bluealsa/hci0/dev_10_9E_3A_30_CB_5C/a2dpsrc/sink: Changing SW avail min: 1 -> 6000
D: ../../../src/asound/bluealsa-pcm.c:231: /org/bluealsa/hci0/dev_10_9E_3A_30_CB_5C/a2dpsrc/sink: Pausing IO thread
D: ../../../src/asound/bluealsa-pcm.c:392: /org/bluealsa/hci0/dev_10_9E_3A_30_CB_5C/a2dpsrc/sink: Stopping
D: ../../../src/asound/bluealsa-pcm.c:161: /org/bluealsa/hci0/dev_10_9E_3A_30_CB_5C/a2dpsrc/sink: IO thread cleanup
D: ../../../src/asound/bluealsa-pcm.c:392: /org/bluealsa/hci0/dev_10_9E_3A_30_CB_5C/a2dpsrc/sink: Stopping
D: ../../../src/asound/bluealsa-pcm.c:592: /org/bluealsa/hci0/dev_10_9E_3A_30_CB_5C/a2dpsrc/sink: Freeing HW
D: ../../../src/asound/bluealsa-pcm.c:443: /org/bluealsa/hci0/dev_10_9E_3A_30_CB_5C/a2dpsrc/sink: Closing
But by -D bluealsa:DEV=10:9E:3A:30:CB:5C To specify the device every time , And through PROFILE=a2dp Appoint profile so much trouble , We can set the default playback device and profile. Edit user profile ~/.asoundrc that will do .
nano ~/.asoundrc
Change the content to :
pcm.!default {
type plug
slave.pcm {
type bluealsa
device "XX:XX:XX:30:CB:5C"
profile "a2dp"
}
}
pcm.fangtang {
type plug
slave.pcm {
type bluealsa
device "XX:XX:XX:30:CB:5C"
profile "a2dp"
}
}
notes : There is also a global configuration file
/etc/asound.conf
1.7 Play MP3 Format Audio
aplay Can't play MP3 Format audio , We need to mplayer
sudo apt install mplayer
mplayer cat.mp3
# Or use alsa Default device
mplayer -ao alsa cat.mp3
# Or specify equipment
mplayer -ao alsa:device=fangtang cat.mp3
1.8 You may need some right debug Useful commands
1.8.1 bluealsa relevant
bluealsa-aplay --list-pcms
bluealsa-aplay --list-devices
bluealsa-aplay -L
1.8.2 bluetoothctl relevant
list: List all interfaces . Use select XX:XX:XX... Choose another interface .devices : List all devices . Use scan on, scan off Find new devices .info XX:XX:XX... : Display the information of the specified device .remove XX:XX:XX... : Remove the specified device . When there is a problem with the equipment , You can debug in this way .connect XX:XX:XX...: Connect the specified device .disconnect XX:XX:XX...: Disconnect the specified device .pair XX:XX:XX...: Pair the specified device .trust XX:XX:XX...: Trust the specified device .power on: open bluetooth Power Supply .scan on: Start scanning devices .agent NoInputNoOutput : Use this mode as Bluetooth sink You can connect directly without intervention .default-agent : Will the current agent Mode as default .discoverable on : Make the current device discoverable .
These commands can be found in sudo bluetoothctl After the [bluetooth] Run in the prompt , Or run it directly on the system command line bluetoothctl command , for example bluetoothctl info, bluetoothctl connect XX:XX:XX....
for example :
[email protected]:~ $ bluetoothctl info
Device XX:XX:XX:30:CB:5C (public)
Name: Sugar cube (6C:7C)
Alias: Sugar cube (6C:7C)
Class: 0x002c0414
Icon: audio-card
Paired: yes
Trusted: yes
Blocked: no
Connected: yes
LegacyPairing: no
UUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)
UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb)
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
Modalias: bluetooth:v000Fp1200d1436
1.8.3 Other
busctl tree org.bluez - View connected devices
[email protected]:~/sound $ bluealsa-aplay --list-pcms
bluealsa:SRV=org.bluealsa,DEV=XX:XX:XX:30:CB:5C,PROFILE=a2dp
Sugar cube (6C:7C), trusted audio-card, playback
A2DP (SBC): S16_LE 2 channels 48000 Hz
View related logs :
dmesg | egrep -i 'blue|firm'
tail -f /var/log/syslog
journalctl -u bluetooth
journalctl | grep blue
service bluetooth status perhaps sudo systemctl status bluetooth View service status
[email protected]:~ $ service bluetooth status
● bluetooth.service - Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-06-15 09:48:02 CST; 5h 2min ago
Docs: man:bluetoothd(8)
Main PID: 386 (bluetoothd)
Status: "Running"
Tasks: 1 (limit: 725)
CGroup: /system.slice/bluetooth.service
└─386 /usr/lib/bluetooth/bluetoothd --noplugin=sap --plugin=a2dp
6 month 15 09:48:02 raspberrypi bluetoothd[386]: Ignoring (cli) battery
6 month 15 09:48:02 raspberrypi bluetoothd[386]: Ignoring (cli) sixaxis
6 month 15 09:48:02 raspberrypi bluetoothd[386]: Bluetooth management interface 1.18 initialized
6 month 15 09:48:02 raspberrypi bluetoothd[386]: Failed to set privacy: Rejected (0x0b)
6 month 15 09:48:02 raspberrypi bluetoothd[386]: Endpoint registered: sender=:1.2 path=/org/bluez/hci0/A2DP/AAC/source/1
6 month 15 09:48:02 raspberrypi bluetoothd[386]: Endpoint registered: sender=:1.2 path=/org/bluez/hci0/A2DP/AAC/source/2
6 month 15 09:48:02 raspberrypi bluetoothd[386]: Endpoint registered: sender=:1.2 path=/org/bluez/hci0/A2DP/SBC/source/1
6 month 15 09:48:02 raspberrypi bluetoothd[386]: Endpoint registered: sender=:1.2 path=/org/bluez/hci0/A2DP/SBC/source/2
6 month 15 11:16:10 raspberrypi bluetoothd[386]: /org/bluez/hci0/dev_10_9E_3A_30_CB_5C/fd0: fd(17) ready
6 month 15 12:41:37 raspberrypi bluetoothd[386]: /org/bluez/hci0/dev_10_9E_3A_30_CB_5C/fd1: fd(17) ready
notes :Failed to set privacy: Rejected (0x0b) Does not affect playback .
Couldn't get BlueALSA PCM: PCM not found error
ALSA lib ../../../src/asound/bluealsa-pcm.c:1313:(_snd_pcm_bluealsa_open) Couldn't get BlueALSA PCM: PCM not found
aplay: main:828: audio open error: Without that equipment
reason : Usually because the device is not connected . Just pair and connect the device , Just OK 了 .
========= The following is more complicated , For reference ===========
2. Install through source code bluealsa
2.1 download bluealsa Source code
git clone https://github.com/Arkq/bluez-alsa.git
2.2 Installation depends on
sudo apt update
sudo apt install git automake autoconf build-essential libtool pkg-config python-docutils
sudo apt install bluez bluez-tools libasound2-dev libbluetooth-dev libdbus-1-dev libglib2.0-dev libsbc-dev
2.3 Compilation and installation
cd bluez-alsa
autoreconf --install --force
mkdir build && cd build
# following configure Choose one of two commands
#../configure --enable-aac --enable-ofono --enable-debug
../configure CFLAGS="-g -O0" LDFLAGS="-g" --enable-debug
make && sudo make install
If configure It uses
--enable-aacOptions , Then you need to compile and installfdk-aac, Otherwise, an error will be reported :cd ~ git clone --depth 1 https://github.com/mstorsjo/fdk-aac cd fdk-aac \ && autoreconf -fiv \ && ./configure \ && make -j$(nproc) \ && sudo make install
2.4 function Bluealsa
$ sudo bluealsa -i hci0 -p a2dp-source
# If the compilation and installation are correct ,sudo bluealsa -S Then the following message will appear
bluealsa: D: ../../src/main.c:580: Starting main dispatching loop
bluealsa: D: ../../src/main.c:112: Acquired D-Bus service name: org.bluealsa
bluealsa: D: ../../src/bluealsa-dbus.c:426: Registering D-Bus manager: /org/bluealsa
bluealsa: D: ../../src/bluez.c:679: Registering battery provider: /org/bluez/hci0/battery
bluealsa: D: ../../src/bluez.c:699: BlueZ battery provider support not available
bluealsa: D: ../../src/bluez.c:493: Creating media endpoint object: /org/bluez/hci0/A2DP/SBC/source/1
bluealsa: D: ../../src/bluez.c:402: Registering media endpoint: /org/bluez/hci0/A2DP/SBC/source/1
bluealsa: D: ../../src/bluez.c:493: Creating media endpoint object: /org/bluez/hci0/A2DP/SBC/source/2
bluealsa: D: ../../src/bluez.c:402: Registering media endpoint: /org/bluez/hci0/A2DP/SBC/source/2
bluealsa: D: ../../src/bluez.c:928: Creating hands-free profile object: /org/bluez/HSP/AudioGateway
bluealsa: D: ../../src/bluez.c:852: Registering hands-free profile: /org/bluez/HSP/AudioGateway
bluealsa: D: ../../src/bluez.c:928: Creating hands-free profile object: /org/bluez/HFP/AudioGateway
bluealsa: D: ../../src/bluez.c:852: Registering hands-free profile: /org/bluez/HFP/AudioGateway
2.5 take pi Join the corresponding user group
sudo adduser pi bluetooth
sudo adduser pi audio
2.6 take bluealsa chkconfig mysqld on
Edit boot file :
sudo nano /etc/rc.local
stay exit Add the following before the line
# Start bluealsa as root <https://github.com/Arkq/bluez-alsa>
export LIBASOUND_THREAD_SAFE=0
/usr/bin/bluealsa -i hci0 -p a2dp-source &
sudo reboot After through ps -ef | grep bluealsa The command confirms that it is running .
Reference material :
- alsa - How to stream sound to a bluetooth device from a raspberry pi zero - Raspberry Pi Stack Exchange
- Using the BlueALSA ALSA pcm plugin · Arkq/bluez-alsa Wiki
- Gitee Download fast /Bluetooth Audio ALSA Backend
- Arkq/bluez-alsa: Bluetooth Audio ALSA Backend
- Help with “Couldn’t get BlueALSA PCM: PCM not found” error · Issue #394 · Arkq/bluez-alsa
6.sound - Sending audio to bluetooth speaker with bluealsa - Ask Ubuntu- pi 3 - Raspberry Pi 3, can’t connect to more than one bluetooth speaker via pulseaudio - Raspberry Pi Stack Exchange
- alsa - How to stream sound to a bluetooth device from a raspberry pi zero - Raspberry Pi Stack Exchange
- Couldn’t get BlueALSA PCM: PCM not found · Issue #553 · Arkq/bluez-alsa
- alsa - I want to allow two instances of mPlayer to play music over a single bluetooth link to a speaker - Raspberry Pi Stack Exchange
- [SOLVED] RPi4 Bluetooth woes - Raspberry Pi Forums
- A script to play all audio formats. You only need the dll’s found at https://github.com/elibroftw/music-caster/tree/master/vlc
- Bluetooth audio on a headless Raspberry Pi using BlueAlsa — introt docs
- Raspberry Pi Bluetooth Speaker: Play Audio Wirelessly using Raspberry Pi(Pi As Bluetooth Sink)
- BlueALSA: Bluetooth-Audio using ALSA (not PulseAudio) - Off-topic - Armbian Community Forums
- dotfiles/bluealsa_dev_select.sh at master · ohel/dotfiles
边栏推荐
- shell编程
- MySQL self incrementing lock
- 123123123
- [database] CTE (common table expression)
- opengauss简易版安装报错
- docker修改挂载到宿主机上的mysql配置文件不生效?
- Queue assistant | product update log in June 2022
- MySQL check whether the table is locked
- Docker modifying the MySQL configuration file attached to the host does not take effect?
- Is it safe to invest in treasury bonds in 2022? How do individuals buy treasury bonds?
猜你喜欢
随机推荐
[database] CTE (common table expression)
Kubernetes scheduling concept and workflow
Experimental flags: --disable_ admission_ control=false --enable_ rm=false --llama_ callback_ port=28000
mySql建表的基本操作 与常见的函数
替换license是否要重启数据库?
UIToolkit中显示汉字
Rust language - slice type (&[u8])
Torth file read vulnerability (cnvd-2020-27769)
软考可以查成绩了,2022年上半年软考成绩查询入口已开通
Database performance test (MySQL)
2万字带你从0到1搭建一套企业级微服务安全框架
Flame diagram analysis Flink backpressure
28. Implement strstr() implement strstr()
曲线曲率展示
How to use Hyper-V in win10 Home Edition
"Niuke | daily question" template stack
Depth cloning and reflection of typescript class objects
Acwing- daily question
QT监听socket事件,使用QSocketNotifier类
Drools(4):Drools基础语法(2)






![[749. Isolate virus]](/img/12/b8c3cdb664f4415d20c2fc5c697a41.png)

![[untitled] reprint](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
