From: liangzhenying <867174124@qq.com> Date: Wed, 9 Apr 2025 03:33:00 +0000 (+0800) Subject: 改了demo,同步最新的SDK X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=7e4d2a7e74043327221ea891a532c145069e784f;p=mirrors%2FIOTBluetooth-iOS.git 改了demo,同步最新的SDK --- diff --git a/IOTBluetooth/IOTBluetooth/Example/Base.lproj/Main.storyboard b/IOTBluetooth/IOTBluetooth/Example/Base.lproj/Main.storyboard index 5a59854..1027518 100644 --- a/IOTBluetooth/IOTBluetooth/Example/Base.lproj/Main.storyboard +++ b/IOTBluetooth/IOTBluetooth/Example/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -286,13 +286,13 @@ - + - + diff --git a/IOTBluetooth/IOTBluetooth/Example/ChatViewController.swift b/IOTBluetooth/IOTBluetooth/Example/ChatViewController.swift index 166739b..204fa45 100644 --- a/IOTBluetooth/IOTBluetooth/Example/ChatViewController.swift +++ b/IOTBluetooth/IOTBluetooth/Example/ChatViewController.swift @@ -19,7 +19,7 @@ class ChatViewController: UIViewController{ var playIndex = 0 var voiceData = NSMutableData() var ttsData = Data() - + var timer: Timer? override func viewDidLoad() { super.viewDidLoad() @@ -79,14 +79,18 @@ class ChatViewController: UIViewController{ tableView.scrollToRow(at: IndexPath(row: list.count - 1, section: 0), at: .none, animated: true) } } - if response.type == 4{ - self.saveToFile() - } +// if response.type == 4{ +// self.saveToFile() +// } } IBAiManager.shared.ttsDataCallBack = { [weak self] data in guard let self = self else {return} self.ttsData.append(data) + self.timer?.invalidate() + self.timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false, block: { [unowned self] _ in + self.saveToFile() + }) } } diff --git a/IOTBluetooth/IOTBluetooth/Example/PLayerManager2.swift b/IOTBluetooth/IOTBluetooth/Example/PLayerManager2.swift new file mode 100644 index 0000000..950e355 --- /dev/null +++ b/IOTBluetooth/IOTBluetooth/Example/PLayerManager2.swift @@ -0,0 +1,61 @@ +//import AVFoundation +// +//class AudioPlayerStreamer { +// public static let shared = AudioPlayerStreamer() +// private var audioEngine: AVAudioEngine! +// private var audioPlayerNode: AVAudioPlayerNode! +// private var audioFormat: AVAudioFormat! +// private var mixerNode: AVAudioMixerNode! +// +// init() { +// // 配置音频格式 +// let sampleRate: Double = 16000 +// let channelCount: AVAudioChannelCount = 1 +// audioFormat = AVAudioFormat(commonFormat:.pcmFormatInt16, sampleRate: sampleRate, channels: channelCount, interleaved: true) +// +// // 初始化音频引擎和播放器节点 +// audioEngine = AVAudioEngine() +// audioPlayerNode = AVAudioPlayerNode() +// mixerNode = AVAudioMixerNode() +// +// audioEngine.attach(audioPlayerNode) +// audioEngine.attach(mixerNode) +// +// // 获取设备的默认输出格式 +// let outputFormat = audioEngine.outputNode.outputFormat(forBus: 0) +// +// // 连接播放器节点到混音器节点,并进行格式转换 +// audioEngine.connect(audioPlayerNode, to: mixerNode, format: audioFormat) +// audioEngine.connect(mixerNode, to: audioEngine.outputNode, format: outputFormat) +// +// do { +// // 启动音频引擎 +// try audioEngine.start() +// audioPlayerNode.play() +// } catch { +// print("Failed to start audio engine: \(error)") +// } +// } +// +// func playAudioData(_ audioData: Data) { +// // 将 Data 转换为 AVAudioPCMBuffer +// guard let audioBuffer = AVAudioPCMBuffer(pcmFormat: audioFormat, frameCapacity: AVAudioFrameCount(audioData.count / Int(audioFormat.streamDescription.pointee.mBytesPerFrame))) else { +// print("Failed to create audio buffer") +// return +// } +// +// // 将 Int16 指针转换为 UInt8 指针 +// let bytePointer = UnsafeMutableRawPointer(audioBuffer.int16ChannelData![0]).assumingMemoryBound(to: UInt8.self) +// audioData.copyBytes(to: bytePointer, count: audioData.count) +// audioBuffer.frameLength = AVAudioFrameCount(audioData.count / Int(audioFormat.streamDescription.pointee.mBytesPerFrame)) +// +// // 将音频缓冲区加入播放器节点进行播放 +// audioPlayerNode.scheduleBuffer(audioBuffer, at: nil, options:.interrupts, completionHandler: nil) +// } +// +// deinit { +// // 停止音频引擎 +// audioEngine.stop() +// audioEngine.reset() +// } +//} diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.pbxproj b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.pbxproj index 66251dd..234467d 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.pbxproj +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.pbxproj @@ -72,6 +72,7 @@ 3F9355B72D38FF2100C54DAB /* IBPush.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F9355B62D38FF1900C54DAB /* IBPush.swift */; }; 3FBD71C52D7E95AC009E6F3C /* IBAiManager2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FBD71C42D7E959E009E6F3C /* IBAiManager2.swift */; }; 3FBD72272D7EE1A4009E6F3C /* PlayerManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FBD72262D7EE1A4009E6F3C /* PlayerManager.swift */; }; + 3FC3C36C2D89291A00C4F447 /* PLayerManager2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FC3C36B2D89290C00C4F447 /* PLayerManager2.swift */; }; 3FCB3D182D7AE0D000D75ABB /* IOTBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A0A39BB2B980BEF006A3B18 /* IOTBluetooth.framework */; }; 3FCB3D1E2D7AE3B300D75ABB /* MixSdk.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3FCB3D142D7ADFD500D75ABB /* MixSdk.framework */; }; 3FCFBFDE2D548D70003FC090 /* pumpkin.lzma in Resources */ = {isa = PBXBuildFile; fileRef = 3FCFBFDD2D548D70003FC090 /* pumpkin.lzma */; }; @@ -187,6 +188,7 @@ 3F9355B62D38FF1900C54DAB /* IBPush.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IBPush.swift; sourceTree = ""; }; 3FBD71C42D7E959E009E6F3C /* IBAiManager2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IBAiManager2.swift; sourceTree = ""; }; 3FBD72262D7EE1A4009E6F3C /* PlayerManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerManager.swift; sourceTree = ""; }; + 3FC3C36B2D89290C00C4F447 /* PLayerManager2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PLayerManager2.swift; sourceTree = ""; }; 3FCB3D0F2D7ADFD500D75ABB /* MixSdk.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = MixSdk.xcodeproj; path = IOTBluetooth/MixSdk/MixSdk/MixSdk.xcodeproj; sourceTree = ""; }; 3FCB3D162D7AE08D00D75ABB /* MixTools.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MixTools.framework; path = IOTBluetooth/MixSdk/MixSdk/MixTools.framework; sourceTree = ""; }; 3FCFBFDD2D548D70003FC090 /* pumpkin.lzma */ = {isa = PBXFileReference; lastKnownFileType = file; path = pumpkin.lzma; sourceTree = ""; }; @@ -377,6 +379,7 @@ 8A1DFF512B9EB4F800B735FF /* AppDelegate.swift */, 8A1DFF552B9EB4F800B735FF /* ViewController.swift */, 3FBD72262D7EE1A4009E6F3C /* PlayerManager.swift */, + 3FC3C36B2D89290C00C4F447 /* PLayerManager2.swift */, 8A34B9262BA2AB66000F66BD /* ConnectViewController.swift */, 8A76B6082BA84C2B0016F2AB /* AbilityViewController.swift */, 3F2AF7F92D57118D00635545 /* ChatViewController.swift */, @@ -721,6 +724,7 @@ 3F2AF82F2D57125D00635545 /* ChatViewController.swift in Sources */, 3F8167242D5DDE1F002936D5 /* IBSpeaker.swift in Sources */, 8A34B9272BA2AB66000F66BD /* ConnectViewController.swift in Sources */, + 3FC3C36C2D89291A00C4F447 /* PLayerManager2.swift in Sources */, 18EF697A2C47A86D00AA0A36 /* IBTools.swift in Sources */, 8A1DFF562B9EB4F800B735FF /* ViewController.swift in Sources */, 8A1DFF522B9EB4F800B735FF /* AppDelegate.swift in Sources */, diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate index 5f7b5ff..fcae70b 100644 Binary files a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate and b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAiManager.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAiManager.swift index e45b9bf..88e0141 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAiManager.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAiManager.swift @@ -259,7 +259,7 @@ extension IBAiManager{ } } //⾳频⽂件回调 - MixSdk.shared.voiceChat.replyCallBack = {[unowned self] data in + MixSdk.shared.voiceChat.ttsCallBack = {[unowned self] data in ttsDataCallBack?(data) } } diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/Example/Example.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist b/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/Example/Example.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist index 8d6b401..c1cbfb0 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/Example/Example.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/Example/Example.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,7 +7,7 @@ Example.xcscheme_^#shared#^_ orderHint - 2 + 1 diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/Example/Example/VoiceChatViewController.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/Example/Example/VoiceChatViewController.swift index 0385f1b..15660b7 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/Example/Example/VoiceChatViewController.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/Example/Example/VoiceChatViewController.swift @@ -33,7 +33,7 @@ class VoiceChatViewController: UIViewController{ let toolBar = SendToolBar() toolBar.textField.text = "写一个800字的作文" - toolBar.textField.text = "你是谁" + toolBar.textField.text = "我们来玩成语接龙吧" toolBar.delegate = self view.addSubview(toolBar) @@ -158,7 +158,7 @@ extension VoiceChatViewController:SendToolBarDelegate{ let range = NSMakeRange(textView.text.count - 1, 1) textView.scrollRangeToVisible(range) - MixSdk.shared.voiceChat.requestToSpeak() +// MixSdk.shared.voiceChat.requestToSpeak() MixSdk.shared.voiceChat.send(content: text) } diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate b/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate index 706014f..97dd682 100644 Binary files a/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate and b/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MSVoiceChat.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MSVoiceChat.swift index d4f7ffb..5f9804b 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MSVoiceChat.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MSVoiceChat.swift @@ -8,7 +8,7 @@ import Foundation /// 语音回复回调 -public typealias MSVoiceChatReplyCallBack = (_ data: Data) -> Void +public typealias MSVoiceChatTtsCallBack = (_ data: Data) -> Void /// 事件回调 public typealias MSVoiceChatEventCallBack = (_ model:MSVoiceChatEvent) -> Void @@ -21,12 +21,12 @@ public class MSVoiceChat { /// 对话回调 public var callBack:MSChatCallBack? /// 语音数据回调 - public var replyCallBack:MSVoiceChatReplyCallBack? + public var ttsCallBack:MSVoiceChatTtsCallBack? /// 连接状态回调 public var connectStateCallBack:MSConnectStateCallBack? - /// 当前出在的事件状态 + /// 当前处在的事件状态 public var currentEvent:MSVoiceChatEvent? /// 设备ID/用户ID @@ -241,8 +241,8 @@ extension MSVoiceChat{ currentEvent = nil; // let url = MSConfig.webSocketUrl(api: "voice-chat/ws",addPlatform: false) - 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)" -// let url = MSConfig.wsBaseURL + "voice-chat/v2.1/ws?platform=raisound&bot_type=\(MixSdk.shared.aiPlatform.voiceChatValue)&is_auth=1&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)" + let url = MSConfig.wsBaseURL + "voice-chat/v2.1/ws?platform=raisound&bot_type=\(MixSdk.shared.aiPlatform.voiceChatValue)&is_auth=1&dt=\(MixSdk.shared.auth.deviceToken)" Logger.log(url) socket = WebSocket(url) @@ -261,7 +261,7 @@ extension MSVoiceChat:WebSocketDelegate{ func webSocketClose(_ code: Int, reason: String, wasClean: Bool) { Logger.log("MSVoiceChat webSocketClose",code,reason,wasClean) - connectStateCallBack?(.disConnected) +// connectStateCallBack?(.disConnected) } func webSocketError(_ error: NSError) { @@ -304,7 +304,7 @@ extension MSVoiceChat:WebSocketDelegate{ func webSocketMessageData(_ data: Data){ // Logger.log("MSVoiceChat receive data ",data) - replyCallBack?(data) + ttsCallBack?(data) } func webSocketPong(){ diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/Pods/Pods.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist b/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/Pods/Pods.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist index eaee3d7..52928e8 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/Pods/Pods.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/Pods/Pods.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,7 +7,7 @@ IQKeyboardManagerSwift-IQKeyboardManagerSwift.xcscheme_^#shared#^_ orderHint - 6 + 2 IQKeyboardManagerSwift.xcscheme_^#shared#^_ @@ -17,7 +17,7 @@ Pods-Example.xcscheme_^#shared#^_ orderHint - 3 + 6 SnapKit-SnapKit_Privacy.xcscheme_^#shared#^_ @@ -27,12 +27,12 @@ SnapKit.xcscheme_^#shared#^_ orderHint - 5 + 3 Toast-Swift.xcscheme_^#shared#^_ orderHint - 1 + 5