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.
91 lines
3.0 KiB
91 lines
3.0 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);
|
|
}
|
|
|
|
/// 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();
|
|
}
|
|
}
|
|
|