前提条件
开始之前,请设置您的设备并为 HFP 音频网关功能配置 DUT。连接远程设备
要连接远程设备,请在bluetoothctl 菜单中运行以下命令:
connect <bt_address>
<bt_address> 是远程设备的蓝牙地址。
示例
要连接 <bt_address> 为 20:19:D8:36:90:40 的已配对远程设备,请运行以下命令:
connect 20:19:D8:36:90:40
[Test]# connect 20:19:D8:36:90:40
Attempting to connect to 20:19:D8:36:90:40
[CHG] Device 20:19:D8:36:90:40 Connected: yes
[CHG] Device 20:19:D8:36:90:40 UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[CHG] Device 20:19:D8:36:90:40 UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device 20:19:D8:36:90:40 UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device 20:19:D8:36:90:40 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 20:19:D8:36:90:40 UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device 20:19:D8:36:90:40 ServicesResolved: yes
[CHG] Device 20:19:D8:36:90:40 Bonded: yes
[CHG] Device 20:19:D8:36:90:40 Paired: yes
[NEW] Endpoint /org/bluez/hci0/dev_20_19_D8_36_90_40/sep1
[NEW] Transport /org/bluez/hci0/dev_20_19_D8_36_90_40/sep1/fd1
Connection successful
[CHG] Transport /org/bluez/hci0/dev_20_19_D8_36_90_40/sep1/fdl State: active
[CHG] Transport /org/bluez/hci0/dev_20_19_D8_36_90_40/sep1/fd1 Volume: 0x0068 (104)
[CHG] Transport /org/bluez/hci0/dev_20_19_D8_36_90_40/sep1/fd1 State: idle
验证音频网关功能
要验证音频网关功能,请执行以下操作:pactl 工具默认不可用。请在您的设备上启用并构建该工具。
-
运行以下命令列出所有声卡,验证 BlueZ 声卡的可用配置文件,并找到其活动配置文件:
示例输出
pactl list cards# pactl list cards Card #65 Name: bluez_card.20_19_D8_36_90_40 Driver: module-bluez5-device.c Owner Module: n/a Properties: device.api = "bluez5" device.bus = "bluetooth" media.class = "Audio/Device" device.name = "bluez_card.20_19_D8_36_90_40" device.description = " MyHeadset" device.alias = " MyHeadset" device.form_factor = "headset" device.string = "20:19:D8:36:90:40 " api.bluez5.icon = "audio-headset" api.bluez5.path = "/org/bluez/hci0/dev_20_19_D8_36_90_40" api.bluez5.address = "20:19:D8:36:90:40" api.bluez5.device = "" api.bluez5.class = "0x240404" api.bluez5.connection = "connected" device.icon_name = "audio-headset-bluetooth" bluez5.profile = "off" spa.object.id = "5" factory.id = "15" client.id = "33" object.id = "36" object.serial = "65" Profiles: off: Off (sinks: 0, sources: 0, priority: 0, available: yes) a2dp-sink: High Fidelity Playback (A2DP Sink, codec SBC) (sinks: 1, sources: 0, priority: 18, available: yes) a2dp-sink-sbc_xq: High Fidelity Playback (A2DP Sink, codec SBC-XQ) (sinks: 1, sources: 0, priority: 17, available: yes) headset-head-unit-cvsd: Headset Head Unit (HSP/HFP, codec CVSD) (sinks: 1, sources: 1, priority: 2, available: yes) headset-head-unit: Headset Head Unit (HSP/HFP, codec mSBC) (sinks: 1, sources: 1, priority: 3, available: yes) Active Profile: a2dp-sink Ports: headset-input: Handsfree (type: Headset, priority: 0, latency offset: 0 usec, available) Properties: port.type = "headset" Part of profile(s): headset-head-unit-cvsd, headset-head-unit headset-output: Headset (type: Headset, priority: 0, latency offset: 0 usec, available) Properties: port.type = "headset" Part of profile(s): a2dp-sink, a2dp-sink-sbc_xq headset-hf-output: Handsfree (type: Headset, priority: 0, latency offset: 0 usec, available) Properties: port.type = "headset" Part of profile(s): headset-head-unit-cvsd, headset-head-unit -
如果活动配置文件为
a2dp-sink(Active Profile: a2dp-sink),请运行以下命令将活动配置文件切换为headset-head-unit:此设置可确保在连接多个配置文件时音频通过 SCO 传输。pactl set-card-profile bluez_card.20_19_D8_36_90_40 headset-head-unit -
运行以下命令验证 BlueZ 声卡的活动配置文件已设置为
headset-head-unit:示例输出pactl list cards# pactl list cards Card #65 Name: bluez_card.20_19_D8_36_90_40 Driver: module-bluez5-device.c Owner Module: n/a Properties: device.api = "bluez5" device.bus = "bluetooth" media.class = "Audio/Device" device.name = "bluez_card.20_19_D8_36_90_40" device.description = " MyHeadset" device.alias = " MyHeadset" device.form_factor = "headset" device.string = "20:19:D8:36:90:40 " api.bluez5.icon = "audio-headset" api.bluez5.path = "/org/bluez/hci0/dev_20_19_D8_36_90_40" api.bluez5.address = "20:19:D8:36:90:40" api.bluez5.device = "" api.bluez5.class = "0x240404" api.bluez5.connection = "connected" device.icon_name = "audio-headset-bluetooth" bluez5.profile = "off" spa.object.id = "5" factory.id = "15" client.id = "33" object.id = "36" object.serial = "65" Profiles: off: Off (sinks: 0, sources: 0, priority: 0, available: yes) a2dp-sink: High Fidelity Playback (A2DP Sink, codec SBC) (sinks: 1, sources: 0, priority: 18, available: yes) a2dp-sink-sbc_xq: High Fidelity Playback (A2DP Sink, codec SBC-XQ) (sinks: 1, sources: 0, priority: 17, available: yes) headset-head-unit-cvsd: Headset Head Unit (HSP/HFP, codec CVSD) (sinks: 1, sources: 1, priority: 2, available: yes) headset-head-unit: Headset Head Unit (HSP/HFP, codec mSBC) (sinks: 1, sources: 1, priority: 3, available: yes) Active Profile: headset-head-unit -
按如下方式创建虚拟 SCO:
a. 运行 SSH。
b. 运行以下命令播放 WAV 文件:
示例 要播放
paplay <file.wav> -vAG_playback.wav文件,请运行以下命令:示例输出paplay AG_playback.wav -vsh-5.1# paplay AG_playback.wav -v Opening a playback stream with sample specification 's16le 2ch 44100Hz' and channel map 'front-left,front-right'. Connection established. Stream successfully created. Buffer metrics: maxlength=4194304, tlength=352800, prebuf=349276, minreq=3528 Using sample spec 's16le 2ch 44100Hz', channel map 'front-left,front-right'. Connected to device bluez_output.20:19:D8:36:90:40 (index: 68, suspended: no). Stream started. Time: 2.003 sec; Latency: 2042009 usec. -
运行以下命令从远程设备接收麦克风数据:
参数
parec -v --rate=<rate> --format=<format> --channels=<channel_number> --file-format=<file_format audio_filepath> --device=<device_name>
| 选项 | 参数 | 描述 | 示例 |
|---|---|---|---|
--rate | <rate> | 播放音频文件的特定采样率。 | 16000 |
--format | <format> | 播放音频文件的特定采样格式。 | s16le |
--channels | <channel_number> | 播放音频文件的特定声道数。 | 1 |
--file-format | <file_format audio_filepath> | 从目录播放音频文件的文件格式。 | wav /data/rec1.wav |
--device | <device_name> | 播放音频文件的源或 sink 的设备名称。 | bluez_input.20:19:D8:36:90:40 |
要从源列表中识别设备名称,请在 SSH 中运行以下命令:示例输出
pactl list sources short
sh-5.1# pactl list sources short
51 alsa_output.platform-sound.HiFi__Speaker__sink.monitor PipeWire s16le 2ch 48000Hz SUSPENDED
52 alsa_input.platform-sound.HiFi__Mic1__source PipeWire s16le 2ch 48000Hz SUSPENDED
65 bluez_input.20:19:D8:36:90:40 PipeWire float32le 1ch 48000Hz SUSPENDED
68 bluez_output.20:19:D8:36:90:40.monitor PipeWire float32le 2ch 48000Hz SUSPENDED
parec -v --rate=16000 --format=s16le --channels=1 --file-format=wav /data/rec1.wav --device=bluez_input.20:19:D8:36:90:40
sh-5.1# parec -v --rate=16000 --format=s16le --channels=1 --file-format=wav /data/rec1.wav --device=bluez_input.20:19:D8:36:90:40
Opening a recording stream with sample specification 's16le 1ch 16000Hz' and channel map 'mono'.
Connection established.
Stream successfully created.
Buffer metrics: maxlength=4194304, fragsize=64000
Using sample spec 's16le 1ch 16000Hz', channel map 'mono'.
Connected to device bluez_input.20:19:D8:36:90:40 (index: 65, suspended: no).
- 播放录制的麦克风数据并验证音频是否清晰。
断开远程设备
要断开远程设备,请在bluetoothctl 菜单中运行以下命令:
disconnect <bt_address>
<bt_address> 是远程设备的蓝牙地址。
示例
要断开 <bt_address> 为 20:19:D8:36:90:40 的已配对远程设备,请运行以下命令:
disconnect 20:19:D8:36:90:40
[MyHeadset]# disconnect 20:19:D8:36:90:40
Attempting to disconnect from 20:19:D8:36:90:40
[DEL] Transport /org/bluez/hci0/dev_20_19_D8_36_90_40/sep1/fd2
[DEL] Endpoint /org/bluez/hci0/dev_20_19_D8_36_90_40/sep1
[CHG] Device 20:19:D8:36:90:40 ServicesResolved: no
Successful disconnected
[CHG] Device 20:19:D8:36:90:40 Connected: no

