改了二代AI开始说话参数
authorliangzhenying <867174124@qq.com>
Wed, 12 Mar 2025 10:16:33 +0000 (18:16 +0800)
committerliangzhenying <867174124@qq.com>
Wed, 12 Mar 2025 10:16:33 +0000 (18:16 +0800)
IOTBluetooth/IOTBluetooth/Example/ChatViewController.swift
IOTBluetooth/IOTBluetooth/IOTBluetooth.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate
IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAiManager.swift
IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MSVoiceChat.swift

index 69de2b7..ab24436 100644 (file)
@@ -64,7 +64,6 @@ class ChatViewController: UIViewController{
             PlayerManager.shared.stop()
         }
         IBAiManager.shared.aiResponse = {[weak self] response in
-            print("ai回复 === \(response.description)")
             guard let self = self else {return}
             if response.type == 1 || response.type == 2{
                 if let model = list.last,model.reponseId == response.reponseId {
index ef75042..5ea63ee 100644 (file)
Binary files a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate and b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate differ
index 86de35c..eb4a912 100644 (file)
@@ -82,6 +82,13 @@ public class IBAiManager{
             else{
                 sendAiState(isValid: true, gptKey: nil)
             }
+            if platform == .chatGPT {
+                MixSdk.shared.chatGpt.changeModel(model:gptModel)
+                MixSdk.shared.setPlatform(platform,key: nil)
+            }
+            else{
+                MixSdk.shared.setPlatform(platform,key: nil)
+            }
         }
     }
 
@@ -120,13 +127,14 @@ public class IBAiManager{
         Logger.log("使用模型:",platform.title)
         useMode?(platform)
         
-        if platform == .chatGPT {
-            MixSdk.shared.chatGpt.changeModel(model:gptModel)
-            MixSdk.shared.setPlatform(platform,key: nil)
-        }
-        else{
-            MixSdk.shared.setPlatform(platform,key: nil)
-        }
+//        if platform == .chatGPT {
+//            MixSdk.shared.chatGpt.changeModel(model:gptModel)
+//            MixSdk.shared.setPlatform(platform,key: nil)
+//        }
+//        else{
+//            MixSdk.shared.setPlatform(platform,key: nil)
+//        }
+        responseId = "\(Date().timeIntervalSince1970)"
         MixSdk.shared.voiceChat.start()
     }
     func stopRecord(_ data:Data){
@@ -140,7 +148,6 @@ public class IBAiManager{
 //        saveRecordData(data: sbcData)
         let pcmData =  MSAudioConvert.sbcTopcm(sbcData)
         if pcmData.count == 0{
-            Logger.log("sbc2pcm失败")
             Logger.log("sbc2pcm失败")
             let model = IBAiResponse(responseId)
             model.type = 0
@@ -226,32 +233,6 @@ extension IBAiManager{
     
 
     func setupChatCallBack(){
-        let chat = MixSdk.shared.chat
-        chat.callBack = {[weak self] model in
-            guard let self = self else {return}
-            Logger.log("\(model.type) : \(model.content ?? "")")
-            
-            if model.type == "start" {
-                reply = ""
-            }
-            else if model.type == "end" {
-                let model = IBAiResponse(responseId)
-                model.type = 4
-                model.state = "end"
-                model.totalContent = reply
-                sendRelpy(model: model)
-            }
-            else if model.type == "middle"{
-                reply += model.content ?? ""
-                let data = IBAiResponse(responseId)
-                data.state = "middle"
-                data.type = 2
-                data.content = model.content ?? ""
-                data.totalContent = reply
-                sendRelpy(model: data)
-            }
-        }
-        
         //事件回调
         MixSdk.shared.voiceChat.callBack = { [weak self] model in
             guard let self = self else {return}
index 253727d..6803b7b 100644 (file)
@@ -55,7 +55,7 @@ public class MSVoiceChat {
     /// 开始任务
     public func start(){
         openWebSocket()
-        setupHeartBeat()
+//        setupHeartBeat()
     }
     
     func setupHeartBeat(){
@@ -98,7 +98,8 @@ public class MSVoiceChat {
         [
             "header":[
                 "trace_id":self.taskId,
-                "event":"Start"
+                "event":"Start",
+                "status": 0,
             ],
             "payload":[
 //                "device_id": "test_device_id", // 设备ID/用户ID
@@ -106,10 +107,10 @@ public class MSVoiceChat {
                 "user_agent": "python", // 浏览器uset-gaent 自定义
                 "dialog_id":dialogId, // 继承上轮对话 空新建一个对话
                 "out_format": "pcm",  // 返回音频格式 支持 pcm、opus
-                "volume": "10", // 音量设置
+                "volume": "100", // 音量设置
                 "sample_rate": 16000, // 返回音频采样率
                 "voice": "zh_female_shuangkuaisisi_moon_bigtts", // 音色配置
-                "simple_response": true, // 设置是否返回增量文本内容,false 实时返回临时内容 true 返回实时增量内容
+                "simple_response": false, // 设置是否返回增量文本内容,false 实时返回临时内容 true 返回实时增量内容
                 "custom_variables": [ // 自定义参数
                     "bot_name": "柒先生"
                 ],
@@ -229,7 +230,8 @@ extension MSVoiceChat{
         currentEvent = nil;
         
 //        let url = MSConfig.webSocketUrl(api: "voice-chat/ws",addPlatform: false)
-        let url = "ws://118.145.158.207:22082/voice-chat/ws?platform=raisound&bot_type=\(2)&is_auth=0&dt=\(MixSdk.shared.auth.deviceToken)"
+//        let url = "ws://118.145.158.207:22082/voice-chat/ws?platform=raisound&bot_type=doubao&is_auth=0&dt=\(MixSdk.shared.auth.deviceToken)"
+        let url = "ws://118.145.158.207:22080/voice-chat/v2.1/ws?platform=raisound&bot_type=\(MixSdk.shared.aiPlatform.voiceChatValue)&is_auth=0&dt=\(MixSdk.shared.auth.deviceToken)"
         Logger.log(url)
         socket = WebSocket(url)
         socket?.delegate = self
@@ -288,7 +290,7 @@ extension MSVoiceChat:WebSocketDelegate{
     }
     
     func webSocketMessageData(_ data: Data){
-        Logger.log("MSVoiceChat receive data ",data)
+//        Logger.log("MSVoiceChat receive data ",data)
         replyCallBack?(data)
     }