Przeglądaj źródła

fix
删除录音字幕还在

harry 3 lat temu
rodzic
commit
1330876cb5

+ 15 - 11
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -454,7 +454,7 @@ public class BFRecordScreenController: BFBaseViewController {
 
         // 录音进度
         recorderManager?.recorderProgrossHandle = { [weak self] progress in
-            BFLog(1, message: "curr:录音进度--\(progress),\(self?.isRecording ?? false)")
+//            BFLog(1, message: "curr:录音进度--\(progress),\(self?.isRecording ?? false)")
             self?.drawProgressIndication(progress: (progress.isNaN || progress.isInfinite) ? 0 : progress)
         }
 
@@ -469,18 +469,20 @@ public class BFRecordScreenController: BFBaseViewController {
             let header = dicResult?["header"] as? [String: Any]
             let payload = dicResult?["payload"] as? [String: Any]
 
-            BFLog(message: "识别结果:) \((payload?["result"])!) startTime:\(self?.recorderManager?.voiceModel?.startCMTime.seconds ?? 0.0)")
+            BFLog(1, message: "识别结果:) \((payload?["result"])!),taskId:\((header?["task_id"] as? String) ?? "taskId"), 识别时间:\((((payload?["begin_time"]) as? Int) ?? 0)) ~ \((((payload?["time"]) as? Int) ?? 0)) startTime:\(self?.recorderManager?.voiceModel?.startCMTime.seconds ?? 0.0)")
             DispatchQueue.main.async {
                 // 1,保存字幕数据 begin_time是开始出现文字的时间,time 是结束文字出现的时间 单位都为毫秒,都是相对于录制音频数据整段时间。self.recorderManager.voiceModel?.startCMTime.seconds 为开始的录制的时间,开始和结束都要加上这个时差
 
                 let newSubtitle = PQEditSubTitleModel()
                 // 任务全局唯一ID,请记录该值,便于排查问题。 每次 startRecorder 和 stopRecoder 之间  task_Id都不会变化
                 newSubtitle.taskID = (header?["task_id"] as? String) ?? ""
-
+                BFLog(1, message: "url:\(URL(fileURLWithPath: audioFilePath ?? "b").deletingPathExtension().lastPathComponent), wavpath:\(URL(fileURLWithPath:self?.recorderManager?.voiceModel?.wavFilePath ?? "aa").deletingPathExtension().lastPathComponent)")
                 // 这里加300ms 是因为返回结果为了切到字,时长提前一些时间,具体时间官方没说和原音频有关系。这里我们先延后300ms 单位:毫秒。
-                if URL(fileURLWithPath: audioFilePath ?? "b").deletingPathExtension().lastPathComponent.contains(URL(fileURLWithPath: self?.recorderManager?.voiceModel?.wavFilePath ?? "aa").deletingPathExtension().lastPathComponent) {
+                if let audioUrl = audioFilePath, URL(fileURLWithPath: audioUrl).deletingPathExtension().lastPathComponent.contains(URL(fileURLWithPath: self?.recorderManager?.voiceModel?.wavFilePath ?? "aa").deletingPathExtension().lastPathComponent) {
                     newSubtitle.timelineIn = (self?.recorderManager?.voiceModel?.startCMTime ?? .zero) + CMTime(seconds: Float64((((payload?["begin_time"]) as? Int) ?? 0) + 300) / 1000.0, preferredTimescale: 1000)
                     newSubtitle.timelineOut = (self?.recorderManager?.voiceModel?.startCMTime ?? .zero) + CMTime(seconds: Float64(((payload?["time"]) as? Int) ?? 0) / 1000.0, preferredTimescale: 1000)
+                    newSubtitle.audioFilePath = audioUrl
+                    BFLog(1, message: "字幕按时回来")
 
                     if (newSubtitle.timelineIn - (self?.recorderManager?.voiceModel?.endCMTime ?? .zero)).seconds > 0.1 {
                         BFLog(1, message: "卡在录音尾巴上了1")
@@ -492,7 +494,8 @@ public class BFRecordScreenController: BFBaseViewController {
                     }) {
                         newSubtitle.timelineIn = voice.startCMTime + CMTime(seconds: Float64((((payload?["begin_time"]) as? Int) ?? 0) + 300) / 1000.0, preferredTimescale: 1000)
                         newSubtitle.timelineOut = voice.startCMTime + CMTime(seconds: Float64(((payload?["time"]) as? Int) ?? 0) / 1000.0, preferredTimescale: 1000)
-
+                        newSubtitle.audioFilePath = voice.wavFilePath
+                        BFLog(1, message: "字幕没及时回来")
                         if (newSubtitle.timelineIn - voice.endCMTime).seconds > 0.1 {
                             BFLog(1, message: "卡在录音尾巴上了1")
                             newSubtitle.timelineIn = newSubtitle.timelineIn - CMTime(seconds: 0.1, preferredTimescale: 1000)
@@ -505,9 +508,9 @@ public class BFRecordScreenController: BFBaseViewController {
                     showText += "..."
                 }
                 newSubtitle.text = showText
-                newSubtitle.audioFilePath = audioFilePath ?? ""
+//                newSubtitle.audioFilePath = audioFilePath ?? ""
 
-                BFLog(message: "添加字幕数据 timelineIn \(newSubtitle.timelineIn) timelineOut \(newSubtitle.timelineOut) text: \(newSubtitle.text) 音频路径为:\(audioFilePath ?? "") 传入的地址:\(self?.recorderManager?.voiceModel?.wavFilePath ?? "aa")")
+                BFLog(1, message: "添加字幕数据 timelineIn \(newSubtitle.timelineIn.seconds) timelineOut \(newSubtitle.timelineOut.seconds) text: \(newSubtitle.text) 音频路径为:\(audioFilePath ?? "bb") 传入的地址:\(self?.recorderManager?.voiceModel?.wavFilePath ?? "aa")")
 
                 newSubtitle.setting = self?.subtitleSettingView.subtitle.setting ?? BFSubTitileSettingModel()
 
@@ -907,9 +910,9 @@ public class BFRecordScreenController: BFBaseViewController {
         BFLog(message: "itemModels[currItemModelIndex].titleStickers  删除前:\(itemModels[currItemModelIndex].titleStickers.count) model.startCMTime.seconds: \(voiceModel.startCMTime.seconds) model.end: \(voiceModel.endCMTime.seconds)")
         var deleteTemp = [(PQEditSubTitleModel, Int)]()
 
-        for (index, title) in itemModels[currItemModelIndex].titleStickers.enumerated() {
-            if title.audioFilePath == voiceModel.wavFilePath {
-                deleteTemp.append((title, index))
+        for (ind, sticker) in itemModels[currItemModelIndex].titleStickers.enumerated() {
+            if sticker.audioFilePath == voiceModel.wavFilePath {
+                deleteTemp.append((sticker, ind))
             }
         }
         // 从原数组中删除
@@ -936,6 +939,7 @@ public class BFRecordScreenController: BFBaseViewController {
             var event = WithDrawModel(type: 3, timestamp: currentAssetProgress.seconds, deletedVoices: [(model, isStopAtRecordRange)])
             event.deletedTittles = deleteTitles(voiceModel: model)
             events.append(event)
+            
             // 注:删除录音后图片素材需要回撤指针进度,同时后面录音往前挪
             if itemModels[currItemModelIndex].mediaType == .IMAGE {
                 let currDuration = model.endCMTime.seconds - model.startCMTime.seconds
@@ -2041,7 +2045,7 @@ public extension BFRecordScreenController {
         } else {
             currentAssetProgress = CMTime(seconds: recordStartPlayTime.seconds + progress, preferredTimescale: 1000)
         }
-        BFLog(1, message: "图片录音进度:\(progress),currentAssetProgress=\(currentAssetProgress),\(itemModels[currItemModelIndex].materialDuraion)")
+        BFLog(message: "图片录音进度:\(progress),currentAssetProgress=\(currentAssetProgress.seconds),\(itemModels[currItemModelIndex].materialDuraion)")
         if itemModels[currItemModelIndex].mediaType == .IMAGE {
             /// 重置进度
             resetCurrentProgress()