You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
5.1 KiB
149 lines
5.1 KiB
import 'dart:typed_data';
|
|
|
|
import 'bluetooth_manager_platform_interface.dart';
|
|
|
|
class BluetoothManager {
|
|
Future<bool> initialize() {
|
|
return BluetoothManagerPlatform.instance.initialize();
|
|
}
|
|
|
|
Future<bool> disconnect() {
|
|
return BluetoothManagerPlatform.instance.disconnect();
|
|
}
|
|
|
|
Future<bool> sendData(Uint8List data) {
|
|
return BluetoothManagerPlatform.instance.sendData(data);
|
|
}
|
|
|
|
Stream<int> onDeviceStatusChanged() {
|
|
return BluetoothManagerPlatform.instance.onDeviceStatusChanged();
|
|
}
|
|
|
|
Stream<Uint8List> onDeviceDataReceived() {
|
|
return BluetoothManagerPlatform.instance.onDeviceDataReceived();
|
|
}
|
|
|
|
Stream<Map> onDeviceCmdEvent() {
|
|
return BluetoothManagerPlatform.instance.onDeviceCmdEvent();
|
|
}
|
|
|
|
Future<List<Map<String, dynamic>>> getBondedDevices() {
|
|
return BluetoothManagerPlatform.instance.getBondedDevices();
|
|
}
|
|
|
|
Future<bool> connectDevice(String deviceId) {
|
|
return BluetoothManagerPlatform.instance.connectDevice(deviceId);
|
|
}
|
|
|
|
Future<bool> setAuthorizedDevices(List<String> deviceIds) {
|
|
return BluetoothManagerPlatform.instance.setAuthorizedDevices(deviceIds);
|
|
}
|
|
|
|
/// 分类音频事件流(spkData=对端 / micData=本端 / mainMicData / ffMicData)。
|
|
/// 与不带类型的 [onDeviceDataReceived] 并存,通话翻译必须用这条。
|
|
Stream<Map> onDeviceAudioEvent() {
|
|
return BluetoothManagerPlatform.instance.onDeviceAudioEvent();
|
|
}
|
|
|
|
/// 启动通话翻译的下行 TTS 发送器(native 负责 G.722 编码与 20ms 节流)
|
|
Future<bool> startCallDownlink() {
|
|
return BluetoothManagerPlatform.instance.startCallDownlink();
|
|
}
|
|
|
|
Future<bool> stopCallDownlink() {
|
|
return BluetoothManagerPlatform.instance.stopCallDownlink();
|
|
}
|
|
|
|
/// 推一段译文 TTS 的 PCM(16k/16bit/mono)下发给耳机。
|
|
/// [leg] 'A' = 己方译文给对端听;'B' = 对端译文给己方听。
|
|
Future<bool> pushTtsPcm(String leg, Uint8List pcm) {
|
|
return BluetoothManagerPlatform.instance.pushTtsPcm(leg, pcm);
|
|
}
|
|
|
|
/// 通话翻译 PCM 原生直连桥(原生 CallPcmBridge):开着时双路 PCM 不再经过 Dart,
|
|
/// 直接交给 azure_speech;译文 PCM 也直接回到下行发送器。
|
|
Future<bool> setCallPcmBridge(bool enabled) {
|
|
return BluetoothManagerPlatform.instance.setCallPcmBridge(enabled);
|
|
}
|
|
|
|
/// EMAI 会话 PCM 原生直连桥(原生 AiPcmBridge):开着时唤醒后的耳机麦 PCM
|
|
/// 不再经过 Dart,直接交给 azure_speech 的百炼客户端。
|
|
Future<bool> setAiPcmBridge(bool enabled) {
|
|
return BluetoothManagerPlatform.instance.setAiPcmBridge(enabled);
|
|
}
|
|
|
|
Future<Map<String, dynamic>> getAiPcmBridgeStats() {
|
|
return BluetoothManagerPlatform.instance.getAiPcmBridgeStats();
|
|
}
|
|
|
|
/// 桥的计数(上行/下行帧数),排查「桥开着但没声音」时看这个。
|
|
Future<Map<String, dynamic>> getCallDownlinkStats() {
|
|
return BluetoothManagerPlatform.instance.getCallDownlinkStats();
|
|
}
|
|
|
|
Future<Map<String, dynamic>> getCallPcmBridgeStats() {
|
|
return BluetoothManagerPlatform.instance.getCallPcmBridgeStats();
|
|
}
|
|
|
|
/// 设备音频直接落盘(原生 PcmWavRecorder):PCM 不再逐帧过平台通道,
|
|
/// 原生解码完就地写 WAV,Dart 只收路径、字节数与电平。
|
|
Future<bool> startFileRecorder({
|
|
required String id,
|
|
required String path,
|
|
required int channels,
|
|
int sampleRate = 16000,
|
|
String? source,
|
|
String? left,
|
|
String? right,
|
|
}) {
|
|
return BluetoothManagerPlatform.instance.startFileRecorder(
|
|
id: id,
|
|
path: path,
|
|
channels: channels,
|
|
sampleRate: sampleRate,
|
|
source: source,
|
|
left: left,
|
|
right: right,
|
|
);
|
|
}
|
|
|
|
/// 停止并回填 WAV 头。null = 这个 id 已经不在了(断连时原生自己收尾过)。
|
|
Future<Map<String, dynamic>?> stopFileRecorder(String id,
|
|
{bool save = true}) {
|
|
return BluetoothManagerPlatform.instance.stopFileRecorder(id, save: save);
|
|
}
|
|
|
|
/// 录音统计流:`{'id', 'bytes', 'level'}`,约 100ms 一条
|
|
Stream<Map> onRecorderEvent() {
|
|
return BluetoothManagerPlatform.instance.onRecorderEvent();
|
|
}
|
|
|
|
/// AI 实时对话事件流(耳机按键唤醒 0x64 / 结束 0xE5 / 调速 / AI 模式下的耳机麦 PCM)。
|
|
/// 与 [onDeviceAudioEvent] 分开:那条是翻译链路的分类音频,两者互斥。
|
|
Stream<Map> onDeviceAiEvent() {
|
|
return BluetoothManagerPlatform.instance.onDeviceAiEvent();
|
|
}
|
|
|
|
/// 启动 AI 下行语音发送器(native 负责 G.722 编码与 20ms 节流)
|
|
Future<bool> startAiDownlink() {
|
|
return BluetoothManagerPlatform.instance.startAiDownlink();
|
|
}
|
|
|
|
Future<bool> stopAiDownlink() {
|
|
return BluetoothManagerPlatform.instance.stopAiDownlink();
|
|
}
|
|
|
|
/// 打断:丢掉队列里还没发的 AI 语音,让耳机立刻安静
|
|
Future<bool> flushAiDownlink() {
|
|
return BluetoothManagerPlatform.instance.flushAiDownlink();
|
|
}
|
|
|
|
/// 推一段 AI 回复的 PCM(16k/16bit/mono)下发给耳机播放
|
|
Future<bool> pushAiPcm(Uint8List pcm) {
|
|
return BluetoothManagerPlatform.instance.pushAiPcm(pcm);
|
|
}
|
|
|
|
Future<Map<String, String>?> getConnectedDevice() {
|
|
return BluetoothManagerPlatform.instance.getConnectedDevice();
|
|
}
|
|
}
|
|
|