骨传导sdk,双击结束对话,结束声音播放
authorliangzhenying <867174124@qq.com>
Tue, 23 Dec 2025 07:36:56 +0000 (15:36 +0800)
committerliangzhenying <867174124@qq.com>
Tue, 23 Dec 2025 07:36:56 +0000 (15:36 +0800)
DeepChordsSdk_iOS/DeepChordsSdk/Example/DeepChordsSdk/DeepChordsAiSdk.swift
DeepChordsSdk_iOS/DeepChordsSdk/Example/Example/VC/ChatVC.swift
DeepChordsSdk_iOS/DeepChordsSdk/Example/Example/tools/DCChatManager.swift

index 8ef5819..2f2cb0e 100644 (file)
@@ -15,8 +15,8 @@ public class DeepChordsAiSdk{
     
     
     public func initSDK(){
-        StarburstConfig.shared().switch(to: .ble)
-        StarburstConfig.shared().appId =  "app_ro4n4nwljr20kwqo"
+//        StarburstConfig.shared().switch(to: .ble)
+//        StarburstConfig.shared().appId =  "app_ro4n4nwljr20kwqo"
         //MARK: 配置缓存路径
         StarburstConfig.shared().sdkFolder = NSTemporaryDirectory()
         StarburstConfig.shared().isDebug = true
@@ -46,7 +46,7 @@ public class DeepChordsAiSdk{
 //            "x-tt-env": "ppe_tischarge_test",
 //        ]
         // voicechat配置
-        StarburstConfig.shared().user_custom_prompt_init = "1.用户位置在上海市杨浦区。2.用户名称叫小明。"
+//        StarburstConfig.shared().user_custom_prompt_init = "1.用户位置在上海市杨浦区。2.用户名称叫小明。"
         
         StarburstSdk.shared().authCallback = {[weak self] (code,msg) in
             self?.authCallback?(Int(code),msg ?? "")
index eb6b763..096d47c 100644 (file)
@@ -83,14 +83,14 @@ class ChatVC: BaseVC {
     @objc func recordAction() {
         self.recordBtn.isSelected = !self.recordBtn.isSelected
         if self.recordBtn.isSelected {
-            DCChat.shared.startChat()
+            DCChatManager.shared.startChat()
         }
         else{
             stopAction()
         }
     }
     func stopAction() {
-        DCChat.shared.stopChat()
+        DCChatManager.shared.stopChat()
     }
     @objc func roleAction(){
         let vc = RoleVC()
index 5a0976d..e2443d0 100644 (file)
@@ -59,27 +59,31 @@ class DCChatManager:NSObject{
         }
     }
     
-    public func stop(){
+    public func stopChat(){
         DCChat.shared.stopChat()
     }
+    public func startChat(){
+        DCChat.shared.startChat()
+    }
     public func getVcSpeekerList(finished:@escaping ([DCRole]?,Bool)->Void){
         DCChat.shared.getVcSpeekerList(finished: finished)
     }
     
-//    func setupSdk(){
-//        PcmSound.sharedInstance().setup(16000, withchannels: 1)
-//        let options: AVAudioSession.CategoryOptions = [.allowBluetooth]
-//        do {
-//            try AVAudioSession.sharedInstance().setCategory(.playback, options: [options])
-//            try AVAudioSession.sharedInstance().setActive(true)
-//        } catch {
-//            DCLogger.debug(error)
-//        }
-//        
-//        setupChat()
-//    }
+    func preparePlay(){
+        PcmSound.sharedInstance().cleanup()
+        PcmSound.sharedInstance().setup(16000, withchannels: 1)
+        
+        var options: AVAudioSession.CategoryOptions = [.allowBluetooth]
+        do {
+            try AVAudioSession.sharedInstance().setCategory(.playback, options: [options])
+            try AVAudioSession.sharedInstance().setActive(true)
+        } catch {
+            DCLogger.debug(error)
+        }
+    }
     
     func setupChat(){
+        preparePlay()
         DCChat.shared.role = role
         DCChat.shared.asrCallback = {[weak self] (text,index) in
             guard let self = self else{return}
@@ -119,16 +123,6 @@ class DCChatManager:NSObject{
                         }
                         DCLogger.debug("收到音频数据", data?.count ?? 0,sampleRate)
                         PcmSound.sharedInstance().feed(data)
-            
-//            if finish {
-//                self.saveToFile(data: self.audioData!)
-//                self.audioData = nil
-//            } else {
-//                if self.audioData == nil {
-//                    self.audioData = Data()
-//                }
-//                self.audioData?.append(data!)
-//            }
         }
         DCChat.shared.codeCallback = {[weak self] code in
             guard let self = self else { return  }
@@ -151,35 +145,36 @@ class DCChatManager:NSObject{
             }
         }
         DCChat.shared.finishCallback = {[weak self] path in
+            self?.preparePlay()
             self?.finishCallback?(path)
         }
         
     }
     
-    func saveToFile(data: Data) {
-        let filePath = NSHomeDirectory() + "/Documents/1.mp3"
-        let url = URL(fileURLWithPath: filePath)
-        do {
-            try data.write(to: url)
-            print("\(filePath)")
-            
-            var options: AVAudioSession.CategoryOptions = [.allowBluetooth]
-            do {
-                try AVAudioSession.sharedInstance().setCategory(.playback, options: [options])
-                try AVAudioSession.sharedInstance().setActive(true)
-            } catch {
-                DCLogger.debug(error)
-            }
-            //这个要传开始播放的tts的dialogid
-            DCChat.shared.startPlayTtsAudio()
-            PlayerManager.shared.play(filePath: filePath,dialoIg:0) { (success,dialoIg) in
-                print("播放结束 = \(success)")
-                DCChat.shared.stopPlayTtsAudio()
-            }
-        } catch let error {
-            print("\(error)")
-        }
-    }
+//    func saveToFile(data: Data) {
+//        let filePath = NSHomeDirectory() + "/Documents/1.mp3"
+//        let url = URL(fileURLWithPath: filePath)
+//        do {
+//            try data.write(to: url)
+//            print("\(filePath)")
+//            
+//            var options: AVAudioSession.CategoryOptions = [.allowBluetooth]
+//            do {
+//                try AVAudioSession.sharedInstance().setCategory(.playback, options: [options])
+//                try AVAudioSession.sharedInstance().setActive(true)
+//            } catch {
+//                DCLogger.debug(error)
+//            }
+//            //这个要传开始播放的tts的dialogid
+//            DCChat.shared.startPlayTtsAudio()
+//            PlayerManager.shared.play(filePath: filePath,dialoIg:0) { (success,dialoIg) in
+//                print("播放结束 = \(success)")
+//                DCChat.shared.stopPlayTtsAudio()
+//            }
+//        } catch let error {
+//            print("\(error)")
+//        }
+//    }
 }
 extension DCChatManager : PcmSoundDelegate {
     func remaining(_ frames: UInt) {