18DB20482C213D730070D571 /* AiMouseAudioRecord.m in Sources */ = {isa = PBXBuildFile; fileRef = 18DB20462C213D730070D571 /* AiMouseAudioRecord.m */; };
18DB20492C213D730070D571 /* AiMouseRecordManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 18DB20472C213D730070D571 /* AiMouseRecordManager.m */; };
18FBC2BB2C38E0FC002240AF /* ChatGptViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18FBC2BA2C38E0FC002240AF /* ChatGptViewController.swift */; };
+ 18FF930C2C39263A0006452C /* cat.png in Resources */ = {isa = PBXBuildFile; fileRef = 18FF930A2C39263A0006452C /* cat.png */; };
F59940004E1C16053FBD42F5 /* Pods_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B555BC40ACD8F31DBCDD1A2 /* Pods_Example.framework */; };
/* End PBXBuildFile section */
18DB20462C213D730070D571 /* AiMouseAudioRecord.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AiMouseAudioRecord.m; sourceTree = "<group>"; };
18DB20472C213D730070D571 /* AiMouseRecordManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AiMouseRecordManager.m; sourceTree = "<group>"; };
18FBC2BA2C38E0FC002240AF /* ChatGptViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatGptViewController.swift; sourceTree = "<group>"; };
+ 18FF930A2C39263A0006452C /* cat.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = cat.png; sourceTree = "<group>"; };
4B555BC40ACD8F31DBCDD1A2 /* Pods_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
759E170040ACED4895C8A49D /* Pods-Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.release.xcconfig"; path = "Target Support Files/Pods-Example/Pods-Example.release.xcconfig"; sourceTree = "<group>"; };
C85BC820E1AA39AC970C9E79 /* Pods-Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.debug.xcconfig"; path = "Target Support Files/Pods-Example/Pods-Example.debug.xcconfig"; sourceTree = "<group>"; };
181188582C1BE80B00C23FAB /* Resource */ = {
isa = PBXGroup;
children = (
+ 18FF930A2C39263A0006452C /* cat.png */,
18C42B582C24166D000D8860 /* input.msbc */,
181188592C1BE80B00C23FAB /* 1.pcm */,
);
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 18FF930C2C39263A0006452C /* cat.png in Resources */,
1811885B2C1BE80B00C23FAB /* 1.pcm in Resources */,
18204BE02C193F9D00F94E69 /* LaunchScreen.storyboard in Resources */,
18204BDD2C193F9D00F94E69 /* Assets.xcassets in Resources */,
view.addSubview(imgView)
imgView.snp.makeConstraints { make in
- make.width.height.equalTo(200)
+ make.width.height.equalTo(320)
make.center.equalToSuperview()
}
}
func getStyleRequest() {
view.makeToastActivity(.center)
// 0:⽂字⽣图,1: ⽂+图⽣图 5: 图⽣图(⻛格变换)
- MixSdk.shared.aigc.getStyle(type: 1) {[weak self] list, error in
+ MixSdk.shared.aigc.getStyle(type: 0) {[weak self] list, error in
self?.view.hideToastActivity()
if let err = error{
print("\(err)")
}
view.makeToastActivity(.center)
let task = MSAigcTask()
- task.subject = "text" // type=5 参数不生效
- task.url = "https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/public/dashscope/test.png" // type=0 不需要提交url type=5 必须提交
- task.type = 1 //0:⽂字⽣图,1: ⽂+图⽣图 5: 图⽣图(⻛格变换)
- task.amount = 2 //⽣成的图⽚数量 type=5 参数不生效
- task.height = 1024//⽣成的图⽚⾼度,type=1时需要是32的倍数。 type=5 参数不生效
- task.width = 1024//⽣成的图⽚宽度,type=1时需要是32的倍数。 type=5 参数不生效
+ task.subject = text // type=5 参数不生效
+ task.type = 0 //0:⽂字⽣图,1: ⽂+图⽣图 5: 图⽣图(⻛格变换)
+ task.height = 320//⽣成的图⽚⾼度,type=1时需要是32的倍数。 type=5 参数不生效
+ task.width = 320//⽣成的图⽚宽度,type=1时需要是32的倍数。 type=5 参数不生效
task.algorithm = style.code //算法id可⽤值⻅get-style
+// task.image_base64 = getImageBase64()//type=0 不需要提交
+
MixSdk.shared.aigc.createTask(task){[weak self] taskId, error in
guard let self = self else {return}
//每隔1秒去查一次结果,直到获取到结果为止
@objc func getResultRequest(_ taskId:String) {
view.makeToastActivity(.center)
- MixSdk.shared.aigc.getResult(taskId: taskId){[weak self] list, error in
+ MixSdk.shared.aigc.getResult(taskId: taskId){[weak self] image, error in
guard let self = self else {return}
self.view.hideToastActivity()
- if let list = list,list.count > 0 {
- print("\(list)")
- self.downLoadFile(url: list[0])
+ if let image = image {
+ self.imgView.image = image
}
else{
self.perform(#selector(getResultRequest), with: taskId, afterDelay: 1)
}
extension AigcViewController {
- func downLoadFile(url:String){
- var request = URLRequest(url: URL(string:url)!)
- request.httpMethod = "Get"
- let task = URLSession.shared.dataTask(with: request) {[weak self] (data, response, error) in
- guard let self = self else {return}
- DispatchQueue.main.sync {
- if let data = data,let img = UIImage(data: data){
- self.imgView.image = img
- }
- }
+// func downLoadFile(url:String){
+// var request = URLRequest(url: URL(string:url)!)
+// request.httpMethod = "Get"
+// let task = URLSession.shared.dataTask(with: request) {[weak self] (data, response, error) in
+// guard let self = self else {return}
+// DispatchQueue.main.sync {
+// if let data = data,let img = UIImage(data: data){
+// self.imgView.image = img
+// }
+// }
+// }
+// task.resume()
+// }
+ func getImageBase64()->String?{
+ let image = UIImage(named: "cat.png")
+ if let base64 = image?.pngData()?.base64EncodedString(){
+ let result = "data:image/png;base64," + base64
+ return result
+ }
+ else{
+ return nil
}
- task.resume()
}
}
+
+
--- /dev/null
+{
+ "images" : [
+ {
+ "filename" : "cat.png",
+ "idiom" : "universal",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "universal",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "universal",
+ "scale" : "3x"
+ }
+ ],
+ "info" : {
+ "author" : "xcode",
+ "version" : 1
+ }
+}
</Locations>
</BreakpointContent>
</BreakpointProxy>
+ <BreakpointProxy
+ BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+ <BreakpointContent
+ uuid = "B79AD572-041B-4C53-88E4-A6F6A6584303"
+ shouldBeEnabled = "Yes"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ filePath = "MixSdk/MixSdk/Tools/MSTool.swift"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "49"
+ endingLineNumber = "49"
+ landmarkName = "base64ToImage(_:)"
+ landmarkType = "7">
+ </BreakpointContent>
+ </BreakpointProxy>
</Breakpoints>
</Bucket>
// Created by incar on 2024/6/14.
//
-import Foundation
+import UIKit
/// aigc任务回调
public typealias MSAigcTaskCallBack = (_ taskId: String?,_ error:MSError?) -> Void
/// aigc查询任务回调
-public typealias MSAigcQueryCallBack = (_ urls: [String]?,_ error:MSError?) -> Void
+public typealias MSAigcQueryCallBack = (_ image: UIImage?,_ error:MSError?) -> Void
/// aigc类
public class MSAigc{
completeHandler(nil,MSError.parsingError)
return
}
- if let list = model.data.results,list.count > 0{
- let urls = list.map { $0.url }
- completeHandler(urls,nil)
+ if let result = model.data.result,let base64 = result.components(separatedBy: "data:image/png;base64,").last,let image = MSTool.base64ToImage(String(base64)){
+ completeHandler(image,nil)
}
else{
completeHandler(nil,.reponseError(model.status, model.data.status))
}
}
}
+
+
}
class MSAigcResultDataModel:Codable{
var status:String = ""
var task_id:String = ""
- var results:[MSAigcResult]?
-}
-/// aigc状态查询
-class MSAigcResult:Codable{
- /// url
- var url:String = ""
+ var result:String?
}
+
class MSAigcStyleModel:Codable{
var status:Int = 0
var data:[MSAigcStyle] = []
public var type:Int = 0
/// 主题,type=5 参数不生效
public var subject:String?
- /// type=0 不需要提交,url type=5 必须提交
- public var url:String?
- /// ⽣成的图⽚数量, type=5 参数不生效
- public var amount:Int = 4
/// ⽣成的图⽚⾼度,type=1时需要是32的倍数。 type=5 参数不生效
public var height:Int = 320
/// ⽣成的图⽚宽度,type=1时需要是32的倍数。 type=5 参数不生效
public var width:Int = 320
/// 算法id可⽤值⻅get-style
public var algorithm:String = "auto"
+ /// type=0 不需要提交, type=5 必须提交。data:image/png;base64,{image_base64} 只要图片内容
+ public var image_base64:String?
public init() { }
}
/// 鉴权管理类
public class MSAuth {
/// 是否已经鉴权
- public private(set) var authorized = false
+ public private(set) var authorized = true
func getUrl(_ api:String)->String{
return "https://app.api.thisiot.com/da/auth/" + api
public var logs: [String] { Logger.logs }
/// SDK 版本号
- public let version: String = "1.0.5"
+ public let version: String = "1.0.6"
/// 默认为 false
public var isDebug: Bool = false {
didSet { Logger.isDebug = isDebug }
// Created by incar on 2024/6/14.
//
-import Foundation
+import UIKit
class MSTool{
static func stringToJson(_ text:String)->[String:Any]?{
return nil
}
}
+
+ static func base64ToImage(_ base64String: String) -> UIImage? {
+ if let data = Data(base64Encoded: base64String),
+ let image = UIImage(data: data) {
+ return image
+ }
+ return nil
+ }
}