2024年11月24日星期日 下午9:55:15

树莓派通过自带bluealsa连接蓝牙音箱接入Home Assistnant(VLC Media Player)

2 年 前
#3563 引用
通过树莓派Raspberry Pi 3B+板载蓝牙自带bluealsa连接蓝牙音箱接入Home Assistnant

I have a bluetooth speaker and I want to use it as media player. I have a Raspberry Server with Debian and Home Assistnant core in host mode.

How could I configure it?



在树莓派上要让 Home Assistant  发声朗读 ,从

硬件

我们需要 3.5mm插口音箱(耳机)或usb口音箱(耳机)、hdmi 显示器、蓝牙音箱。


软件

我们需要一个媒体播放器以及 tts ( 将文字转化为语音的服务 )



硬件连接

首先你要把可以播放声音的设备连接到树莓派上。使用有源音箱或者无源的耳机都可以。我使用的是耳塞,连接到树莓派的3.5mm音频输出接口上,如下图所示:

http://www.codelast.com/wp-content/uploads/2016/12/raspberry_pi_3.5mm_audio.png

Prerequisites

A bluetooth speaker


https://blog.csdn.net/weixin_45820944/article/details/104236412

https://jasiek.me/2014/10/04/bluetooth-console-on-a-raspberry-pi-using-a-usb-adapter.html

While playing with my Raspberry PI, I looked at different networking options available – Ethernet is great, if your house is already cabled, Wi-Fi is great if it isn’t (but on the other hand, not all adapters work reliably and they pull a lot of power, and generate a bit of heat).


sudo bluetoothctl
pair  9A:07:65:B4:21:EC
trust 9A:07:65:B4:21:EC
connect 9A:07:65:B4:21:EC

select 9A:07:65:B4:21:EC

exit

树莓派3B+连接蓝牙音箱


bluetoothctl  // 蓝牙配置工具
power on // 开启蓝牙
agent on // 开启客户端
scan on   // 开启扫描和发现
pair XX:XX:XX:XX:XX   // 配对发现的设备
connect XX:XX:XX:XX:XX // 连接蓝牙设备
trust XX:XX:XX:XX:XX //信任设备,下次自动连接
info XX:XX:XX:XX:XX  //显示已连接的设备信息


systemctl status bluetooth
sudo systemctl restart bluetooth

systemctl status bluealsa
sudo systemctl restart bluealsa

other
sudo apt-get install bluealsa


useful links

案列:基于树莓派bluealsa的连接天猫精灵蓝牙音箱,在多块TF卡测试安装过,已连接天猫精灵稳定使用数月,未遇爆音、丢音、失声。

https://bbs.hassbian.com/thread-5375-1-1.html
https://bbs.hassbian.com/thread-5375-1-1.html
0
2 年 前
#3564 引用
Part 1:打通Raspberry树莓派连接蓝牙音箱并能播放声音之路

how to connect a Linux system with a bluetooth speaker or headset. This is no different with PiOs (Raspian).

You have two options: either use PulseAudio (fat, inflates a PiOS-lite installation by 50%), or bluez-alsa. Don't use "bluesalsa", an early fork of "bluez-alsa" which worked with Stretch, was broken with Buster and was removed from Bullseye.

树莓派连接蓝牙音箱基于bluealsa做的,感觉使用这种方式比较简单,没啥坑。

Your bluetooth device should be up and running now. To verify that the adapter was recognized by the kernel and is operational, do the following:

step 1:查看树莓派 3B+是否具备蓝牙模块

以下命令以获取Raspberry Pi蓝牙设备信息
hciconfig

# hciconfig
hci0:  Type: Primary  Bus: UART
  BD Address: B8:27:EB:2A:96:FA  ACL MTU: 1021:8  SCO MTU: 64:1
  UP RUNNING
  RX bytes:399416 acl:129 sco:0 events:46871 errors:0
  TX bytes:48625050 acl:90983 sco:0 commands:641 errors:0


Step 2:查看树莓派是否有自带的bluealsa

sudo apt policy bluealsa

output

root@raspberrypi:~# sudo apt policy bluealsa
bluealsa:
  已安装:0.9
  候选: 0.9
  版本列表:
*** 0.9 500
        500 http://archive.raspberrypi.org/debian stretch/main armhf Packages
        100 /var/lib/dpkg/status



Step 3;查看bluealsa状态,显示active(running)


systemctl status bluealsa



root@raspberrypi:~# systemctl status bluealsa
● bluealsa.service - BluezALSA proxy
   Loaded: loaded (/lib/systemd/system/bluealsa.service; static; vendor preset: enabled)
   Active: active (running) since Tue 2022-03-22 00:33:43 CST; 19h ago
Main PID: 577 (bluealsa)
    Tasks: 4 (limit: 4915)
   CGroup: /system.slice/bluealsa.service
           └─577 /usr/bin/bluealsa

0
2 年 前
#3565 引用
1
0
2 年 前
#3566 引用
Step 2. Find bluetooth speaker 连接蓝牙音箱

打开蓝牙工具

sudo bluetoothctl



root@raspberrypi:~# sudo bluetoothctl
[NEW] Controller B8:27:E8:2A:a6:FA raspberrypi [default]
[bluetooth]#



打开蓝牙扫描

scan on

运行后可以立即开启蓝牙扫描服务。这个服务会定时扫描周围的蓝牙设备,当扫描到新设备时会添加[NEW]标签:

会扫到一堆蓝牙设备,找到自己的蓝牙音箱,例如标红的那个就是我的音箱:


[CHG] Device 4D:B8:6A:17:1A:74 RSSI: -62
[CHG] Device F0:59:BC:38:A9:0E RSSI: -97
[CHG] Device 38:E6:0A:3B:38:78 RSSI: -88
[NEW] Device 11:58:02:B8:02:54 HAVIT M8
[CHG] Device 38:F9:D3:8A:C6:4B RSSI: -72
[CHG] Device 4D:B8:6A:17:1A:74 ManufacturerData Key: 0x004c
[CHG] Device 4D:B8:6A:17:1A:74 ManufacturerData Value: 0c 0e 08 7f c9 11 8d ca b7 cd 5c e8 e8 26 86 6d …&.m
[CHG] Device 67:2A:0A:5F:79:44 RSSI: -46



这个服务会定时扫描周围的蓝牙设备,当扫描到新设备时会添加[NEW]标签。

通过扫描还可以显示扫描到的蓝牙设备的信号强度和设备商。其中RSSI(Received Signal Strength Indication,接收的信号强度指示)是信号强度,数值越接近0,信号强度越大。



[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:2A:96:FA Discovering: yes
[NEW] Device AC:4D:16:65:54:F6 S6971df687649d654C





0
2 年 前
#3573 引用
how to find the bluetooth device  MAC adress

先关闭蓝牙音箱

再打开蓝牙音箱

等几秒钟,出现了:


[NEW] Device 9A:07:65:B4:21:EC BT73
0
2 年 前
#3574 引用
trust 9A:07:65:B4:21:EC



[bluetooth]# trust 9A:07:65:B4:21:EC
[CHG] Device 9A:07:65:B4:21:EC Trusted: yes
Changing 9A:07:65:B4:21:EC trust succeeded

0
2 年 前
#3575 引用
connect 9A:07:65:B4:21:EC





[bluetooth]# connect 9A:07:65:B4:21:EC
Attempting to connect to 9A:07:65:B4:21:EC
[CHG] Device 9A:07:65:B4:21:EC Connected: yes
[CHG] Device 9A:07:65:B4:21:EC Modalias: bluetooth:v05D6p000Ad0240
[CHG] Device 9A:07:65:B4:21:EC UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device 9A:07:65:B4:21:EC UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 9A:07:65:B4:21:EC UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device 9A:07:65:B4:21:EC UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device 9A:07:65:B4:21:EC ServicesResolved: yes
[CHG] Device 9A:07:65:B4:21:EC Paired: yes
Connection successful
[BT73]#

0
2 年 前
#3576 引用
Playing Sound Through a Bluetooth Speaker
Sending Sound to Bluetooth Audio Devices


aplay -D bluealsa:DEV=蓝牙设备mac地址,自己修改,PROFILE=A2DP test.wav

aplay -D bluealsa:DEV=9A:07:65:B4:21:EC,PROFILE=A2DP test.wav



root@raspberrypi:~# aplay -D bluealsa:DEV=9A:07:65:B4:21:EC,PROFILE=A2DP test.wav
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo



0
2 年 前
#3577 引用
扫描完毕后可以通过scan off关闭扫描服务

exit
0
2 年 前
#3578 引用
aplay -D bluealsa:DEV=蓝牙设备mac地址,自己修改,PROFILE=A2DP test.wav

aplay -D bluealsa:DEV=9A:07:65:B4:21:EC,PROFILE=A2DP test.wav



root@raspberrypi:~# aplay -D bluealsa:DEV=9A:07:65:B4:21:EC,PROFILE=A2DP test.wav
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo



0