deepchords sdk完善注释
authorliangzhenying <867174124@qq.com>
Wed, 14 Jan 2026 08:10:26 +0000 (16:10 +0800)
committerliangzhenying <867174124@qq.com>
Wed, 14 Jan 2026 08:10:26 +0000 (16:10 +0800)
ShenYin/DeepChordsSdk/DCBleManager.swift
ShenYin/DeepChordsSdk/DCBleRecord.swift
ShenYin/DeepChordsSdk/DCCallRecord.swift
ShenYin/DeepChordsSdk/DCChat.swift
ShenYin/DeepChordsSdk/DCChinse2En.swift
ShenYin/DeepChordsSdk/DCDevice.swift
ShenYin/DeepChordsSdk/DCLogger.swift
ShenYin/DeepChordsSdk/DCMusic.swift
ShenYin/DeepChordsSdk/DCPhoneRecord.swift
ShenYin/DeepChordsSdk/DeepChordsAiSdk.swift
ShenYin/DeepChordsSdk/ReceiveManager.swift [deleted file]

index 21420f4..cab5481 100644 (file)
@@ -46,13 +46,13 @@ public class DCBleManager{
     }
 }
 
-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()
     }
@@ -65,7 +65,7 @@ public extension DCBleManager{
 //        }
 //
 //    }
-    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{
@@ -84,7 +84,7 @@ public extension DCBleManager{
         }
     }
     
-    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 {
index d2eae43..38d2d81 100644 (file)
@@ -7,6 +7,7 @@
 
 import StarburstSdk
 
+/// 蓝牙录音管理类
 public class DCBleRecord {
     public static let shared = DCBleRecord()
     /// 语⾔编码,默认为普通话(zh-CN),auto_lang自动识别
@@ -114,7 +115,6 @@ public class DCBleRecord {
     
     /// 0x00实时录音,0x0c通话录音
     public func start(type:Int,recordPath:String?){
-        
             asrList = []
             asrText = ""
             
@@ -127,8 +127,9 @@ public class DCBleRecord {
         let config = StarburstBleAsrConfig()
         config.type = type
         StarburstSdk.shared().startDeviceRecord(config)
-        
     }
+    
+    /// 结束录音
     public func stop(){
         StarburstSdk.shared().stopDeviceRecord()
     }
index 3b482a3..cd7c0fb 100644 (file)
@@ -7,6 +7,7 @@
 
 import StarburstSdk
 
+/// 通话录音
 public class DCCallRecord {
     public static let shared = DCCallRecord()
     /// 语⾔编码,默认为普通话(zh-CN),auto_lang自动识别
@@ -116,22 +117,22 @@ public class DCCallRecord {
         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()
     }
index 44db924..65b5732 100644 (file)
@@ -7,6 +7,7 @@
 
 import StarburstSdk
 
+/// 角色模型
 public class DCRole{
     /// 音色id
     public var sid:String = ""
@@ -29,6 +30,7 @@ public class DCRole{
     }
 }
 
+/// 对话类
 public class DCChat{
     public static let shared = DCChat()
     var speakerList = [DCRole]()
@@ -58,6 +60,9 @@ public class DCChat{
     }
 }
 extension DCChat{
+    
+    /// 获取音色
+    /// - Parameter finished: 结果回调
     public func getVcSpeekerList(finished:@escaping ([DCRole]?,Bool)->Void){
         StarburstSdk.shared().getVcSpeekerList { (list, success) in
             if success,let list = list {
@@ -121,16 +126,24 @@ extension DCChat{
         }
     }
 
+    
+    /// 开始对话
     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)
     }
index c6b114b..3c3c98b 100644 (file)
@@ -8,9 +8,15 @@
 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) {
@@ -51,6 +57,8 @@ public class DCChinse2En {
     var translateList : [(String,Int)] = []
     var translateText = ""
     
+    
+    /// 开始
     public func start(){
         let config = StarburstAsrConfig()
         config.isTranslate = isTranslate
@@ -90,6 +98,8 @@ public class DCChinse2En {
             self?.interruptionCallBack?()
         }
     }
+    
+    /// 结束
     public func stop(){
         StarburstSdk.shared().stopRecordAsr {[weak self] filePath in
             DCLogger.debug("文件录音保存路径 \(filePath ?? "")")
index 9b557ed..eb6cc0c 100644 (file)
@@ -10,27 +10,27 @@ import Foundation
 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
@@ -56,8 +56,9 @@ public class DCDevice{
          }
          DCBleManager.shared.send(sender)
      }
-     ///
-     ///
+     
+     /// 获取电池
+     /// - Parameter finished: 结果回调
     public func getBatery(finished:@escaping ((Int,Int)?)->Void){
         var head: UInt8 = 0xBA
         var cmd: UInt8 = 0x09
@@ -84,6 +85,9 @@ public class DCDevice{
         }
         DCBleManager.shared.send(sender)
     }
+     
+     /// 获取软件版本
+     /// - Parameter finished: 结果回调
     public func getSoftVersion(finished:@escaping (String?)->Void){
         var head: UInt8 = 0xBA
         var cmd: UInt8 = 0x0A
@@ -110,6 +114,9 @@ public class DCDevice{
         }
         DCBleManager.shared.send(sender)
     }
+     
+     /// 获取硬件版本
+     /// - Parameter finished: 结果回调
     public func getHardVersion(finished:@escaping (String?)->Void){
         var head: UInt8 = 0xBA
         var cmd: UInt8 = 0x0A
@@ -137,7 +144,11 @@ public class DCDevice{
         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
@@ -164,12 +175,11 @@ public class DCDevice{
         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
@@ -195,7 +205,13 @@ public class DCDevice{
         }
         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
@@ -227,6 +243,9 @@ public class DCDevice{
          }
          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
index 6319ca8..7d7aee6 100644 (file)
@@ -34,7 +34,7 @@ public class DCLogger {
                 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)
             
@@ -45,7 +45,6 @@ public class DCLogger {
 
 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))]: ")
index afc82d2..58b5776 100644 (file)
@@ -6,6 +6,8 @@
 //
 import Foundation
 
+
+/// 音乐模型
 public class DCMusic:Codable{
     /// id
     public var id:UInt16 = 0
@@ -19,6 +21,8 @@ public class DCMusic:Codable{
 
 extension DCDevice{
     
+    /// 获取音乐数
+    /// - Parameter finished: 结果回调
     public func getTotalMusic(finished:@escaping (Int?)->Void){
         var head: UInt8 = 0xBA
         var cmd: UInt8 = 0x10
@@ -44,6 +48,12 @@ extension DCDevice{
         }
         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
@@ -98,9 +108,11 @@ extension DCDevice{
         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
@@ -128,6 +140,9 @@ extension DCDevice{
         }
         DCBleManager.shared.send(sender)
     }
+    
+    /// 获取音乐播放模式
+    /// - Parameter finished: 结果回调
     public func getMusicPlayMode(finished:@escaping (UInt8?,Bool)->Void){
         var head: UInt8 = 0xBA
         var cmd: UInt8 = 0x10
@@ -156,6 +171,10 @@ extension DCDevice{
         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
@@ -213,6 +232,9 @@ extension DCDevice{
             DCBleManager.shared.send(sender)
         }
     }
+    
+    /// 音乐暂停播放
+    /// - Parameter finished: 结果回调
     public func musicPause(finished:@escaping (Bool)->Void){
         var head: UInt8 = 0xBA
         var cmd: UInt8 = 0x10
@@ -238,6 +260,11 @@ extension DCDevice{
         }
         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
index 4046440..060a62a 100644 (file)
@@ -7,6 +7,7 @@
 import StarburstSdk
 
 public class DCPhoneRecord {
+    /// 单利
     public static let shared = DCPhoneRecord()
     /// 语⾔编码,默认为普通话(zh-CN),auto_lang自动识别
     public var fromLanguage:String = "zh-CN"
@@ -26,7 +27,7 @@ public class DCPhoneRecord {
     public var translateDataCallback:((Data)->Void)?
     /// 状态码回调
     public var codeCallback:((Int)->Void)?
-    /// 打断
+    /// 打断回调
     public var interruptionCallBack:(()->Void)?
     /// 录音文件回调
     public var filePathCallBack:((String?)->Void)?
@@ -37,6 +38,8 @@ public class DCPhoneRecord {
     var translateList : [(String,Int)] = []
     var translateText = ""
     
+    
+    /// 开始
     public func start(){
         let config = StarburstAsrConfig()
         config.isTranslate = isTranslate
@@ -100,6 +103,8 @@ public class DCPhoneRecord {
             self?.interruptionCallBack?()
         }
     }
+    
+    /// 停止
     public func stop(){
         StarburstSdk.shared().stopRecordAsr {[weak self] filePath in
             DCLogger.debug("文件录音保存路径 \(filePath ?? "")")
index 7f50d91..3447238 100644 (file)
@@ -14,7 +14,7 @@ public class DeepChordsAiSdk{
     }
     public var isDebug:Bool = false{
         didSet{
-            StarburstConfig.shared().isDebug = isDebug
+            StarburstConfig.shared().isDebug = false
             DCLogger.isDebug = isDebug
         }
     }
diff --git a/ShenYin/DeepChordsSdk/ReceiveManager.swift b/ShenYin/DeepChordsSdk/ReceiveManager.swift
deleted file mode 100644 (file)
index e482cd6..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-//
-//  ReceiveManager.swift
-//  DeepChordsSdk
-//
-//  Created by liangshi on 2025/11/25.
-//
-import Foundation
-
-class ReceiveManager{
-    
-    
-    static func receiveData(_ data:Data){
-        
-    }
-}