说在前面,很全面的树莓派蓝牙连接教程,你遇到的所有树莓派蓝牙连接相关问题都可以在下面这两篇网址中找到解答。
Bluetooth Audio with Rasbian Stretch on the Raspberry Pi 3
想利用树莓派和蓝牙音箱(Tmall genie BOOM),实现语音互动功能,所以首先第一步是树莓派连接蓝牙音箱,并进行语音播放功能实现。
树莓派连接蓝牙音箱
首先确认树莓派上的蓝牙驱动版本,如果遇到奇奇怪怪的问题建议先升级驱动版本。
sudo bluetoothctl -v
进入蓝牙控制界面。依次上电、扫描、配对、加入信任列表、连接
bluetoothctl
power on
scan on
devices //查看device mac
pair <device mac>
trust <devide mac>
connect <device mac>
如果配对、连接失败,报错 org.bluez.Error.Failed,原因为已经连接过需要手动删除已连接
remove <device id>
蓝牙语音播放
播放的问题比较多,我暂时没有设置蓝牙音箱为默认语音播放器。采用命令行播放。
首先修改:.asuondrc 文件,设置pcm的output 为蓝牙输出模式 。
pi@raspberrypi:~ $ cat ~/.asoundrc
pcm.!default {
type asym
playback.pcm {
type plug
slave.pcm "output"
}
capture.pcm {
type plug
slave.pcm "input"
}
}
pcm.output {
type bluealsa
device "device mac" //你的蓝牙mac
profile "a2dp"
}
ctl.!default {
type bluealsa
}
采用命令行,播放:
aplay -D bluealsa:DEV=D4:4B:B6:91:51:08,PROFILE=a2dp Front_Center.wav
标准的命令行是,如下
aplay -D bluealsa:HCI=hci0,DEV=30:21:3E:31:C6:2B,PROFILE=a2dp test16.wav
但是我这里会报错,所以我删除HCI参数,进行播放,成功。