}
}
-public extension DCBleManager{
- func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
+extension DCBleManager{
+ public func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
DCLogger.debug("蓝牙已连接 \(peripheral)")
connectPeripheral = peripheral
}
- func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) {
+ public func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) {
DCLogger.debug("蓝牙已断开 \(peripheral)")
StarburstSdk.shared().bleDisConnected()
}
// }
//
// }
- func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
+ public func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
if let list = service.characteristics{
DCLogger.debug("发现特征",list)
for char in list{
}
}
- func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
+ public func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
// DCLogger.debug("收 ",characteristic.uuid,characteristic.value?.joined() ?? "")
guard let data = characteristic.value else { return }
if data.count > 4 && data[0] == 0xBA {
import StarburstSdk
+/// 蓝牙录音管理类
public class DCBleRecord {
public static let shared = DCBleRecord()
/// 语⾔编码,默认为普通话(zh-CN),auto_lang自动识别
/// 0x00实时录音,0x0c通话录音
public func start(type:Int,recordPath:String?){
-
asrList = []
asrText = ""
let config = StarburstBleAsrConfig()
config.type = type
StarburstSdk.shared().startDeviceRecord(config)
-
}
+
+ /// 结束录音
public func stop(){
StarburstSdk.shared().stopDeviceRecord()
}
import StarburstSdk
+/// 通话录音
public class DCCallRecord {
public static let shared = DCCallRecord()
/// 语⾔编码,默认为普通话(zh-CN),auto_lang自动识别
StarburstSdk.shared().inputPcmData(data)
}
- /// 0x00实时录音,0x0c通话录音
+
+ /// 开始录音
public func start(){
-
asrList = []
asrText = ""
-
asrOtherList = []
asrOtherText = ""
setupRecord()
let config = StarburstBleAsrConfig()
- config.type = 0x0c
+ config.type = 0x0c// 0x00实时录音,0x0c通话录音
StarburstSdk.shared().startDeviceRecord(config)
}
+ /// 结束录音
public func stop(){
StarburstSdk.shared().stopDeviceRecord()
}
import StarburstSdk
+/// 角色模型
public class DCRole{
/// 音色id
public var sid:String = ""
}
}
+/// 对话类
public class DCChat{
public static let shared = DCChat()
var speakerList = [DCRole]()
}
}
extension DCChat{
+
+ /// 获取音色
+ /// - Parameter finished: 结果回调
public func getVcSpeekerList(finished:@escaping ([DCRole]?,Bool)->Void){
StarburstSdk.shared().getVcSpeekerList { (list, success) in
if success,let list = list {
}
}
+
+ /// 开始对话
public func startChat(){
setupChat()
DCDevice.shared.startChat()
}
+
+ /// 结束对话
public func stopChat(){
StarburstSdk.shared().stopVoiceChat(self.dialogId)
}
+
+ /// 开始播放tts
public func startPlayTtsAudio(){
StarburstSdk.shared().startPlayTtsAudio(self.dialogId)
}
+
+ /// 结束播放tts
public func stopPlayTtsAudio(){
StarburstSdk.shared().stopPlayTtsAudio(self.dialogId)
}
import StarburstSdk
+/// 响应模型
public class DCResponseModel {
+ /// 文本
public var text:String = ""
+
+ /// 索引
public var index:Int = 0
+
+ /// 是否结束
public var definite:Bool = false
init(text: String, index: Int, definite: Bool) {
var translateList : [(String,Int)] = []
var translateText = ""
+
+ /// 开始
public func start(){
let config = StarburstAsrConfig()
config.isTranslate = isTranslate
self?.interruptionCallBack?()
}
}
+
+ /// 结束
public func stop(){
StarburstSdk.shared().stopRecordAsr {[weak self] filePath in
DCLogger.debug("文件录音保存路径 \(filePath ?? "")")
public class DCDevice{
public static let shared = DCDevice()
- /// ai事件回调
- /// 0x01(打开AI对话)
-// 0x02(关闭AI对话)
-// 0x03(打开耳机录音)
-// 0x04(关闭耳机录音)
+ /// ai事件回调:0x01(打开AI对话),0x02(关闭AI对话),0x03(打开耳机录音),0x04(关闭耳机录音)
public var eventCallback:((UInt8)->Void)?
- public var muiscPlayCallback:((UInt16,UInt16,UInt16)->Void)?
+ /// 音乐播放进度回调
+ public var muiscPlayCallback:((_ index:UInt16,_ pro:UInt16,_ duration:UInt16)->Void)?
///
func receiveNotice(_ data:Data){
if data[1] == 0x10,data[2] == 0x06{
let index = UInt16(data[3...4].int)
let pro = UInt16(data[5...6].int)
- let total = UInt16(data[7...8].int)
- DCLogger.debug("播放进度index = \(index),total = \(total),pro = \(pro)")
- muiscPlayCallback?(index,total,pro)
+ let duration = UInt16(data[7...8].int)
+ DCLogger.debug("播放进度index = \(index),pro = \(pro),duration = \(duration)")
+ muiscPlayCallback?(index,pro,duration)
}
}
}
extension DCDevice{
+
+ /// 握手
+ /// - Parameter finished: 握手回调
public func handShake(finished:@escaping ((Bool)?)->Void){
var head: UInt8 = 0xBA
var cmd: UInt8 = 0x11
}
DCBleManager.shared.send(sender)
}
- ///
- ///
+
+ /// 获取电池
+ /// - Parameter finished: 结果回调
public func getBatery(finished:@escaping ((Int,Int)?)->Void){
var head: UInt8 = 0xBA
var cmd: UInt8 = 0x09
}
DCBleManager.shared.send(sender)
}
+
+ /// 获取软件版本
+ /// - Parameter finished: 结果回调
public func getSoftVersion(finished:@escaping (String?)->Void){
var head: UInt8 = 0xBA
var cmd: UInt8 = 0x0A
}
DCBleManager.shared.send(sender)
}
+
+ /// 获取硬件版本
+ /// - Parameter finished: 结果回调
public func getHardVersion(finished:@escaping (String?)->Void){
var head: UInt8 = 0xBA
var cmd: UInt8 = 0x0A
DCBleManager.shared.send(sender)
}
- /// state 0关闭,1打开
+
+ /// 查找设备
+ /// - Parameters:
+ /// - state: 0x00关闭,0x01打开
+ /// - finished: 结果回调
public func findDevice(state:UInt8,finished:@escaping (Bool)->Void){
var head: UInt8 = 0xBA
var cmd: UInt8 = 0x0B
DCBleManager.shared.send(sender)
}
- /// type, 0x00(正常模式)
- // 0x01(流行)
- // 0x02(经典)
- // 0x03(爵士)
- // 0x04(摇滚)
- // 0x05(自定义)
+
+ /// 设置eq
+ /// - Parameters:
+ /// - type:0x00(正常模,0x01(流行),0x02(经典),0x03(爵士),0x04(摇滚),0x05(自定义)
+ /// - finished: 结果回调
public func setEQ(type:UInt8,finished:@escaping (Bool)->Void){
var head: UInt8 = 0xBA
var cmd: UInt8 = 0x0C
}
DCBleManager.shared.send(sender)
}
- /// vaue,只有自定义才有,索引 0-9(对应10段EQ调节)(-12~12)
+
+
+ /// 设置自定义eq
+ /// - Parameters:
+ /// - index: 索引 0-9(对应10段EQ调节)
+ /// - value: -12~12
+ /// - finished: 结果回调
public func setCustomEQ(index:UInt8,value:Int,finished:@escaping (Bool)->Void){
var head: UInt8 = 0xBA
var cmd: UInt8 = 0x0C
}
DCBleManager.shared.send(sender)
}
+
+ /// 获取eq
+ /// - Parameter finished: 结果回调,如果type值为0x05自定义,value才有值
public func getEQ(finished:@escaping ((type:UInt8,value:[Int])?,Bool)->Void){
var head: UInt8 = 0xBA
var cmd: UInt8 = 0x0E
return ""
}
}
- let path = foldPath + "Example_\(Date().format(.middle)).log"
+ let path = foldPath + "DeepChordsSdk_iOS_\(Date().format(.middle)).log"
if !FileManager.default.fileExists(atPath: path) {
FileManager.default.createFile(atPath: path, contents: nil, attributes: nil)
extension DCLogger {
public static func debug(_ logs: Any..., line: Int = #line, separator: String = " ", terminator: String = "\n") {
-
if DCLogger.isDebug {
objc_sync_enter(DCLogger.shared)
print(DCLogger.shared.dateString, terminator: " [DeepChordsSdk-\(String(format: "%03d", line))]: ")
//
import Foundation
+
+/// 音乐模型
public class DCMusic:Codable{
/// id
public var id:UInt16 = 0
extension DCDevice{
+ /// 获取音乐数
+ /// - Parameter finished: 结果回调
public func getTotalMusic(finished:@escaping (Int?)->Void){
var head: UInt8 = 0xBA
var cmd: UInt8 = 0x10
}
DCBleManager.shared.send(sender)
}
+
+ ///
+ /// - Parameters:
+ /// - size: 页大小
+ /// - index: 页码
+ /// - finished: 结果回调
public func getMusicList(size:UInt8,index:UInt16,finished:@escaping ([DCMusic]?,Bool)->Void){
var head: UInt8 = 0xBA
var cmd: UInt8 = 0x10
DCBleManager.shared.send(sender)
}
- // 0x00:顺序循环
- // 0x01:随机
- // 0x02:单曲
+
+ /// 设置音乐播放模型
+ /// - Parameters:
+ /// - mode: 0x00:顺序循环, 0x01:随机, 0x02:单曲
+ /// - finished: 结果回调
public func setMusicPlayMode(mode:UInt8,finished:@escaping (Bool)->Void){
var head: UInt8 = 0xBA
var cmd: UInt8 = 0x10
}
DCBleManager.shared.send(sender)
}
+
+ /// 获取音乐播放模式
+ /// - Parameter finished: 结果回调
public func getMusicPlayMode(finished:@escaping (UInt8?,Bool)->Void){
var head: UInt8 = 0xBA
var cmd: UInt8 = 0x10
DCBleManager.shared.send(sender)
}
+ /// 播放音乐
+ /// - Parameters:
+ /// - index: 音乐索引
+ /// - finished: 播放结果
public func musicPlay(index:UInt16?,finished:@escaping (UInt16?,Bool)->Void){
if let index = index {
var head: UInt8 = 0xBA
DCBleManager.shared.send(sender)
}
}
+
+ /// 音乐暂停播放
+ /// - Parameter finished: 结果回调
public func musicPause(finished:@escaping (Bool)->Void){
var head: UInt8 = 0xBA
var cmd: UInt8 = 0x10
}
DCBleManager.shared.send(sender)
}
+
+ /// 删除音乐
+ /// - Parameters:
+ /// - list: 音乐id
+ /// - finished: 结果回调
public func musicDelete(list:[UInt16],finished:@escaping (Bool)->Void){
var head: UInt8 = 0xBA
var cmd: UInt8 = 0x10
import StarburstSdk
public class DCPhoneRecord {
+ /// 单利
public static let shared = DCPhoneRecord()
/// 语⾔编码,默认为普通话(zh-CN),auto_lang自动识别
public var fromLanguage:String = "zh-CN"
public var translateDataCallback:((Data)->Void)?
/// 状态码回调
public var codeCallback:((Int)->Void)?
- /// 打断
+ /// 打断回调
public var interruptionCallBack:(()->Void)?
/// 录音文件回调
public var filePathCallBack:((String?)->Void)?
var translateList : [(String,Int)] = []
var translateText = ""
+
+ /// 开始
public func start(){
let config = StarburstAsrConfig()
config.isTranslate = isTranslate
self?.interruptionCallBack?()
}
}
+
+ /// 停止
public func stop(){
StarburstSdk.shared().stopRecordAsr {[weak self] filePath in
DCLogger.debug("文件录音保存路径 \(filePath ?? "")")
}
public var isDebug:Bool = false{
didSet{
- StarburstConfig.shared().isDebug = isDebug
+ StarburstConfig.shared().isDebug = false
DCLogger.isDebug = isDebug
}
}
+++ /dev/null
-//
-// ReceiveManager.swift
-// DeepChordsSdk
-//
-// Created by liangshi on 2025/11/25.
-//
-import Foundation
-
-class ReceiveManager{
-
-
- static func receiveData(_ data:Data){
-
- }
-}