From 673a65b5c9484077fce24da2a8869ac3124f67bd Mon Sep 17 00:00:00 2001 From: liangzhenying <867174124@qq.com> Date: Tue, 18 Mar 2025 10:24:11 +0800 Subject: [PATCH] =?utf8?q?=E6=94=B9=E4=BA=86voicechat=E9=87=8D=E8=BF=9E?= =?utf8?q?=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../MixSdk/MixSdk/MixSdk/MSVoiceChat.swift | 18 ++++++------------ .../MixSdk/MixSdk/MixSdk/MixSdk.swift | 18 +++++++++++++----- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MSVoiceChat.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MSVoiceChat.swift index 1b490cd..d4f7ffb 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MSVoiceChat.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MSVoiceChat.swift @@ -63,7 +63,7 @@ public class MSVoiceChat { timer = Timer.scheduledTimer(withTimeInterval: MSConfig.wsHeartBeatTime, repeats: true) { [weak self] _ in guard let self = self else {return} if socket?.readyState == .open{ -// self.socket?.ping() + self.socket?.send(text: "") } else{ self.openWebSocket() @@ -101,7 +101,6 @@ public class MSVoiceChat { "status": 0, ], "payload":[ -// "device_id": "test_device_id", // 设备ID/用户ID "device_id": deviceId, // 设备ID/用户ID "user_agent": "python", // 浏览器uset-gaent 自定义 "dialog_id":dialogId, // 继承上轮对话 空新建一个对话 @@ -141,6 +140,8 @@ public class MSVoiceChat { /// 发送内容 /// - Parameter content: 内容 public func send(content:String){ + MixSdk.shared.voiceChat.requestToSpeak() + let params:[String:Any] = [ "header": [ "trace_id": self.taskId, @@ -162,10 +163,11 @@ public class MSVoiceChat { /// 打断,请求说话 public func requestToSpeak(){ if socket?.readyState == .open{ - //self.socket?.ping() sendSpeakCMD() } else{ + //还没连接 + Logger.log("还没连接!!!!!!!!!!!") self.openWebSocket() DispatchQueue.main.asyncAfter(deadline: .now() + 2) { self.sendSpeakCMD() @@ -282,14 +284,6 @@ extension MSVoiceChat:WebSocketDelegate{ currentEvent = model } - -// if model.event == "RespondingEnded"{ -// let tmpModel = MSChatModel() -// tmpModel.type = "end" -// tmpModel.content = nil -// lastChatModel = tmpModel -// callBack?(tmpModel) -// } if model.event == "RespondingContent",let payload = model.payload,let text = payload.text{ if let finish = payload.finished,finish == false { let tmpModel = MSChatModel() @@ -314,7 +308,7 @@ extension MSVoiceChat:WebSocketDelegate{ } func webSocketPong(){ - //Logger.log("MSVoiceChat Pong") + Logger.log("MSVoiceChat Pong") } func webSocketEnd(_ code: Int, reason: String, wasClean: Bool, error: NSError?){ diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MixSdk.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MixSdk.swift index e569d86..fb00329 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MixSdk.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MixSdk.swift @@ -235,11 +235,19 @@ public class MixSdk:NSObject { /// - key: key值 public func setPlatform(_ platform:MSPlatform,key:String? = nil){ Logger.log("\nplatform = \(platform) \n key= \(key ?? "")") - aiPlatform = platform - aiKey = key - - if platform != .chatGPT{ - setupWebsoket() + if platform == .chatGPT{ + aiPlatform = platform + aiKey = key + } + else { + if (platform == aiPlatform){ +// setupWebsoket() + } + else{ + aiPlatform = platform + aiKey = key + setupWebsoket() + } } } -- 2.17.1