|
@@ -0,0 +1,70 @@
|
|
|
+//
|
|
|
+// BFRecordScreenViewModel.swift
|
|
|
+// Pods
|
|
|
+//
|
|
|
+// Created by ak on 2021/12/7.
|
|
|
+//
|
|
|
+
|
|
|
+import Foundation
|
|
|
+import BFFramework
|
|
|
+import ObjectMapper
|
|
|
+import RealmSwift
|
|
|
+import BFVideoEditKit
|
|
|
+public class BFRecordScreenViewModel:NSObject{
|
|
|
+
|
|
|
+
|
|
|
+ /// 分段识别录音
|
|
|
+ /// - Parameters:
|
|
|
+ /// - sectionIndex: 段落id
|
|
|
+ /// - locationPaths: 分段录音
|
|
|
+ /// - completeHander: <#completeHander description#>
|
|
|
+ /// - Returns: description
|
|
|
+ class public func batchUploadRecordVoiceMatarialData(beginTime: CMTime, locationPath: String, completeHander: @escaping (_ subTitleList: List<PQEditVisionTrackMaterialsModel>?, _ msg: String?) -> Void) {
|
|
|
+
|
|
|
+ BFLog(message: "录音文件开始上传--\(locationPath)")
|
|
|
+
|
|
|
+ if !FileManager.default.fileExists(atPath:documensDirectory + locationPath) {
|
|
|
+ BFLog(message: "上传录音-录音文件不存在")
|
|
|
+ } else {
|
|
|
+
|
|
|
+ let assert = AVURLAsset(url: URL(fileURLWithPath: documensDirectory + locationPath), options: nil)
|
|
|
+ let voiceMaterials: PQEditVisionTrackMaterialsModel = PQEditVisionTrackMaterialsModel()
|
|
|
+ voiceMaterials.locationPath = locationPath
|
|
|
+ voiceMaterials.type = "voice"
|
|
|
+ voiceMaterials.duration = assert.duration.seconds * 1_000_000
|
|
|
+ BFLog(message: "上传录音-开始上传录音")
|
|
|
+ PQVideoEditViewModel.uploadMatarialData(isBatchUpload: false, materialData: voiceMaterials) { _, _, _, _, _, _, matarialInfo, _ in
|
|
|
+ let materialType: String = "\(matarialInfo?["materialType"] ?? "")"
|
|
|
+ let localPath: String = "\(matarialInfo?["localPath"] ?? "")"
|
|
|
+
|
|
|
+ BFLog(message: "上传录音-录音上传返回--\(String(describing: matarialInfo))")
|
|
|
+ if matarialInfo != nil, matarialInfo?.keys.contains("localPath") ?? false, materialType == StickerType.VOICE.rawValue && localPath.contains("_noise_") {
|
|
|
+ BFLog(message: "上传录音-录音上传成功开始转化字幕")
|
|
|
+ let materialId: String = "\(matarialInfo?["materialId"] ?? "")"
|
|
|
+ let duration: Float64 = Float64("\(matarialInfo?["duration"] ?? "")") ?? 0
|
|
|
+ PQVideoEditViewModel.transferAudioMaterialToTextData(Int64(materialId) ?? 0, dutation: duration) { _, _, subTitleList, _ in
|
|
|
+ BFLog(message: "上传录音-字幕转化完成:\(subTitleList.count)")
|
|
|
+
|
|
|
+ if subTitleList.count > 0 {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // dispatchGroup.notify(queue: DispatchQueue.main) {
|
|
|
+ // BFLog(message: "语音均已识别完成")
|
|
|
+ // let subTitleList: List<PQEditVisionTrackMaterialsModel> = List<PQEditVisionTrackMaterialsModel>.init()
|
|
|
+ // BFLog(message: "tempSubTitles == \(String(describing: tempSubTitles.first))")
|
|
|
+ // tempSubTitles.forEach { tempItems in
|
|
|
+ // tempItems.forEach { item in
|
|
|
+ // subTitleList.append(item)
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // completeHander(sectionIndex, subTitleList, nil)
|
|
|
+ // }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|