改了demo,同步最新的SDK v21
authorliangzhenying <867174124@qq.com>
Wed, 9 Apr 2025 03:33:00 +0000 (11:33 +0800)
committerliangzhenying <867174124@qq.com>
Wed, 9 Apr 2025 03:33:00 +0000 (11:33 +0800)
IOTBluetooth/IOTBluetooth/Example/Base.lproj/Main.storyboard
IOTBluetooth/IOTBluetooth/Example/ChatViewController.swift
IOTBluetooth/IOTBluetooth/Example/PLayerManager2.swift [new file with mode: 0644]
IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.pbxproj
IOTBluetooth/IOTBluetooth/IOTBluetooth.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate
IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAiManager.swift
IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/Example/Example.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist
IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/Example/Example/VoiceChatViewController.swift
IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate
IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/MixSdk/MixSdk/MSVoiceChat.swift
IOTBluetooth/IOTBluetooth/IOTBluetooth/MixSdk/Pods/Pods.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist

index 5a59854..1027518 100644 (file)
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22154" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="N0z-3Q-0cV">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="23504" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="N0z-3Q-0cV">
     <device id="retina6_12" orientation="portrait" appearance="light"/>
     <dependencies>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22130"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23506"/>
         <capability name="Safe area layout guides" minToolsVersion="9.0"/>
         <capability name="System colors in document resources" minToolsVersion="11.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
             <color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
         </systemColor>
         <systemColor name="opaqueSeparatorColor">
-            <color red="0.77647058820000003" green="0.77647058820000003" blue="0.7843137255" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+            <color red="0.77647058823529413" green="0.77647058823529413" blue="0.78431372549019607" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
         </systemColor>
         <systemColor name="systemBackgroundColor">
             <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
         </systemColor>
         <systemColor name="systemGray2Color">
-            <color red="0.68235294120000001" green="0.68235294120000001" blue="0.69803921570000005" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+            <color red="0.68235294117647061" green="0.68235294117647061" blue="0.69803921568627447" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
         </systemColor>
     </resources>
 </document>
index 166739b..204fa45 100644 (file)
@@ -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 (file)
index 0000000..950e355
--- /dev/null
@@ -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()
+//    }
+//}
index 66251dd..234467d 100644 (file)
@@ -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 */; };
                3F9355B62D38FF1900C54DAB /* IBPush.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IBPush.swift; sourceTree = "<group>"; };
                3FBD71C42D7E959E009E6F3C /* IBAiManager2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IBAiManager2.swift; sourceTree = "<group>"; };
                3FBD72262D7EE1A4009E6F3C /* PlayerManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerManager.swift; sourceTree = "<group>"; };
+               3FC3C36B2D89290C00C4F447 /* PLayerManager2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PLayerManager2.swift; sourceTree = "<group>"; };
                3FCB3D0F2D7ADFD500D75ABB /* MixSdk.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = MixSdk.xcodeproj; path = IOTBluetooth/MixSdk/MixSdk/MixSdk.xcodeproj; sourceTree = "<group>"; };
                3FCB3D162D7AE08D00D75ABB /* MixTools.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MixTools.framework; path = IOTBluetooth/MixSdk/MixSdk/MixTools.framework; sourceTree = "<group>"; };
                3FCFBFDD2D548D70003FC090 /* pumpkin.lzma */ = {isa = PBXFileReference; lastKnownFileType = file; path = pumpkin.lzma; sourceTree = "<group>"; };
                                8A1DFF512B9EB4F800B735FF /* AppDelegate.swift */,
                                8A1DFF552B9EB4F800B735FF /* ViewController.swift */,
                                3FBD72262D7EE1A4009E6F3C /* PlayerManager.swift */,
+                               3FC3C36B2D89290C00C4F447 /* PLayerManager2.swift */,
                                8A34B9262BA2AB66000F66BD /* ConnectViewController.swift */,
                                8A76B6082BA84C2B0016F2AB /* AbilityViewController.swift */,
                                3F2AF7F92D57118D00635545 /* ChatViewController.swift */,
                                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 */,
index 5f7b5ff..fcae70b 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 e45b9bf..88e0141 100644 (file)
@@ -259,7 +259,7 @@ extension IBAiManager{
             }
         }
         //⾳频⽂件回调
-        MixSdk.shared.voiceChat.replyCallBack = {[unowned self] data in
+        MixSdk.shared.voiceChat.ttsCallBack = {[unowned self] data in
             ttsDataCallBack?(data)
         }        
     }
index 8d6b401..c1cbfb0 100644 (file)
@@ -7,7 +7,7 @@
                <key>Example.xcscheme_^#shared#^_</key>
                <dict>
                        <key>orderHint</key>
-                       <integer>2</integer>
+                       <integer>1</integer>
                </dict>
        </dict>
 </dict>
index 0385f1b..15660b7 100644 (file)
@@ -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)
 
             }
index 706014f..97dd682 100644 (file)
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
index d4f7ffb..5f9804b 100644 (file)
@@ -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?
     
-    /// å½\93å\89\8då\87º在的事件状态
+    /// å½\93å\89\8då¤\84在的事件状态
     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(){
index eaee3d7..52928e8 100644 (file)
@@ -7,7 +7,7 @@
                <key>IQKeyboardManagerSwift-IQKeyboardManagerSwift.xcscheme_^#shared#^_</key>
                <dict>
                        <key>orderHint</key>
-                       <integer>6</integer>
+                       <integer>2</integer>
                </dict>
                <key>IQKeyboardManagerSwift.xcscheme_^#shared#^_</key>
                <dict>
@@ -17,7 +17,7 @@
                <key>Pods-Example.xcscheme_^#shared#^_</key>
                <dict>
                        <key>orderHint</key>
-                       <integer>3</integer>
+                       <integer>6</integer>
                </dict>
                <key>SnapKit-SnapKit_Privacy.xcscheme_^#shared#^_</key>
                <dict>
                <key>SnapKit.xcscheme_^#shared#^_</key>
                <dict>
                        <key>orderHint</key>
-                       <integer>5</integer>
+                       <integer>3</integer>
                </dict>
                <key>Toast-Swift.xcscheme_^#shared#^_</key>
                <dict>
                        <key>orderHint</key>
-                       <integer>1</integer>
+                       <integer>5</integer>
                </dict>
        </dict>
 </dict>