|
@@ -7,11 +7,36 @@
|
|
|
|
|
|
import Combine
|
|
import Combine
|
|
import Alamofire
|
|
import Alamofire
|
|
|
|
+//let actionInfoDict:[String:Any] = [
|
|
|
|
+// "code":200,
|
|
|
|
+// "message": "Success",
|
|
|
|
+// "result": [
|
|
|
|
+// "actionType":"music_create",
|
|
|
|
+// "comments": "Success",
|
|
|
|
+// "costTime":15,
|
|
|
|
+// "createdTimestamp":1741338454,
|
|
|
|
+// "id":1536,
|
|
|
|
+// "percent":1,
|
|
|
|
+// "request":"{\"prompt\": \"Create a Techno ringtone with a repetitive bassline, crisp hi-hats, and subtle synth textures. Use a BPM of 125-130 for a sleek, modern sound., Create a uplifting and modern music track blending Pop, Electronic, and Ambient elements. Use a BPM of 100-120, a catchy melody with synth or piano, warm harmonies, and a mix of electronic and organic sounds. Ensure a clear structure (Intro, Verse, Chorus, Outro) and a light, positive vibe suitable for background or casual listening\", \"duration\": 5}",
|
|
|
|
+// "response":"{\"coverUrl\": \"https://be-aigc.s3-accelerate.amazonaws.com/f0fb7739-a5cc-4805-9b68-b4a5890eb285.png\", \"title\": \"Neon Pulse\\\" \\n\\\"Horizon Glow\", \"musicUrl\": \"https://be-aigc.s3-accelerate.amazonaws.com/c47d40dd-d07c-4edc-a6d9-8382438149d1.wav\"}",
|
|
|
|
+// "status":"success"
|
|
|
|
+// ]
|
|
|
|
+//]
|
|
|
|
+
|
|
|
|
+let actionInfoDict:[String:Any] = [
|
|
|
|
+ "actionType":"music_create",
|
|
|
|
+ "comments": "Success",
|
|
|
|
+ "costTime":15,
|
|
|
|
+ "createdTimestamp":1741338454,
|
|
|
|
+ "id":1536,
|
|
|
|
+ "percent":1,
|
|
|
|
+ "request":"{\"prompt\": \"Create a Techno ringtone with a repetitive bassline, crisp hi-hats, and subtle synth textures. Use a BPM of 125-130 for a sleek, modern sound., Create a uplifting and modern music track blending Pop, Electronic, and Ambient elements. Use a BPM of 100-120, a catchy melody with synth or piano, warm harmonies, and a mix of electronic and organic sounds. Ensure a clear structure (Intro, Verse, Chorus, Outro) and a light, positive vibe suitable for background or casual listening\", \"duration\": 5}",
|
|
|
|
+ "response":"{\"coverUrl\": \"https://be-aigc.s3-accelerate.amazonaws.com/f0fb7739-a5cc-4805-9b68-b4a5890eb285.png\", \"title\": \"Neon Pulse\\\" \\n\\\"Horizon Glow\", \"musicUrl\": \"https://be-aigc.s3-accelerate.amazonaws.com/c47d40dd-d07c-4edc-a6d9-8382438149d1.wav\"}",
|
|
|
|
+ "status":"success"
|
|
|
|
+]
|
|
|
|
|
|
class TSGeneralRintoneVM {
|
|
class TSGeneralRintoneVM {
|
|
-
|
|
|
|
- var audioPlayer: TSAudioPlayer?
|
|
|
|
-
|
|
|
|
|
|
+
|
|
var creatRequest:Request?
|
|
var creatRequest:Request?
|
|
var queryRequest:Request?
|
|
var queryRequest:Request?
|
|
var stopNetwork = false
|
|
var stopNetwork = false
|
|
@@ -24,15 +49,14 @@ class TSGeneralRintoneVM {
|
|
|
|
|
|
stateDatauPblished = (.start,nil)
|
|
stateDatauPblished = (.start,nil)
|
|
stateDatauPblished = (.progressString(generating(progress: 0.0)),nil)
|
|
stateDatauPblished = (.progressString(generating(progress: 0.0)),nil)
|
|
-
|
|
|
|
- kDelayOnMainThread(2.0) {
|
|
|
|
- self.stateDatauPblished = (.failed("error?.localizedDescription" ?? ""),nil)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// kDelayOnMainThread(2.0) {
|
|
// kDelayOnMainThread(2.0) {
|
|
-// self.stateDatauPblished = (.success(nil),TSActionInfoModel())
|
|
|
|
|
|
+// self.stateDatauPblished = (.failed("error?.localizedDescription" ?? ""),nil)
|
|
// }
|
|
// }
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ kDelayOnMainThread(1.0) {
|
|
|
|
+ let infoModel = TSActionInfoModel(JSON: actionInfoDict)
|
|
|
|
+ self.stateDatauPblished = (.success(nil),infoModel)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -41,11 +65,11 @@ class TSGeneralRintoneVM {
|
|
aiText = text
|
|
aiText = text
|
|
let postDict:[String : Any] = [
|
|
let postDict:[String : Any] = [
|
|
"prompt":text,
|
|
"prompt":text,
|
|
- "width":10
|
|
|
|
|
|
+ "duration":5
|
|
]
|
|
]
|
|
stateDatauPblished = (.start,nil)
|
|
stateDatauPblished = (.start,nil)
|
|
stateDatauPblished = (.progressString(generating(progress: 0.0)),nil)
|
|
stateDatauPblished = (.progressString(generating(progress: 0.0)),nil)
|
|
- creatRequest = TSNetworkShared.post(urlType: .textPicCreate,parameters: postDict) { [weak self] data,error in
|
|
|
|
|
|
+ creatRequest = TSNetworkShared.post(urlType: .musicCreate,parameters: postDict) { [weak self] data,error in
|
|
guard let self = self else { return }
|
|
guard let self = self else { return }
|
|
if let dataDict = data as? [String:Any] ,
|
|
if let dataDict = data as? [String:Any] ,
|
|
dataDict.safeInt(forKey: "code") == 200,
|
|
dataDict.safeInt(forKey: "code") == 200,
|
|
@@ -110,36 +134,3 @@ class TSGeneralRintoneVM {
|
|
return "Generating \(progressInt)%"
|
|
return "Generating \(progressInt)%"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-extension TSGeneralRintoneVM {
|
|
|
|
-
|
|
|
|
- func playRingtone(ringtone:String?) {
|
|
|
|
- if let ringtone = ringtone {
|
|
|
|
- self.audioPlayer?.stop()
|
|
|
|
- TSCommonTool.downloadAndCacheFile(from: ringtone) { [self] path, error in
|
|
|
|
- if let path = path {
|
|
|
|
- //播放
|
|
|
|
- if let url = URL(string: path) {
|
|
|
|
- self.audioPlayer = TSAudioPlayer(url: url)
|
|
|
|
- self.audioPlayer?.setLoop(true)
|
|
|
|
- self.audioPlayer?.setVolume(1.0)
|
|
|
|
- dePrint(self.audioPlayer?.duration)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }else{
|
|
|
|
- //暂停
|
|
|
|
- self.audioPlayer?.stop()
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- func changeAudioState(isPlay:Bool) {
|
|
|
|
- if isPlay {
|
|
|
|
- self.audioPlayer?.play()
|
|
|
|
- }else{
|
|
|
|
- self.audioPlayer?.pause()
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|