Ver Fonte

1.取消自动跳转下一个素材功能

wenweiwei há 3 anos atrás
pai
commit
ff479cab87

+ 4 - 4
BFRecordScreenKit/Classes/BFVideoThumbProgressStrategy.swift

@@ -19,12 +19,12 @@ class BFVideoThumbProgressStrategy: BFVideoThumbProgressStrategyProtocol {
 
         if assetDuration > 0, assetDuration <= 10 {
             count = 5
-        } else if assetDuration >= 10, assetDuration < 60 {
+        } else if assetDuration > 10, assetDuration <= 60 {
             count = 10
-        } else if assetDuration >= 60, assetDuration < 300 {
+        } else if assetDuration > 60, assetDuration <= 300 {
             count = 20
-        } else if assetDuration >= 300 {
-            count = 30
+        } else if assetDuration > 300 {
+            count = 50
         }
 
         return count

+ 35 - 15
BFRecordScreenKit/Classes/BFVoiceRecordManager.swift

@@ -46,7 +46,7 @@ class BFVoiceRecordManager: NSObject {
             BFLog(message: "文件夹不存在 \(recorderFilePath)")
             createDirectory(path: recorderFilePath)
         }
-        recorderFilePath.append("recorder_\(Date().timeIntervalSince1970).wav")
+        recorderFilePath.append("recorder_\(Date().timeIntervalSince1970).pcm")
         BFLog(1, message: "开始录音 \(recorderFilePath)")
         
         BFLog(1, message: "开始录制")
@@ -85,33 +85,53 @@ extension BFVoiceRecordManager: BFRecorderManagerDelegate {
                 cancelRecordHandle?(nil)
             }else{
                 
-                // 处理降噪
-                let noiseFilePath = outfile.replacingOccurrences(of: ".wav", with: "_noise.wav")
-                BFLog(1, message: "降噪后地址:\(noiseFilePath) 原地址:\(outfile)")
-                NXNoiseReduction().denoise(outfile, outFile: noiseFilePath)
+                var  beginRecordTime1 = Date()
+               
+                //1转wav
+                let wavFilePath = outfile.replacingOccurrences(of: ".pcm", with: ".wav")
+                BFPcmToWaveTool().pcmToWav(inFileName: outfile, outFileName: wavFilePath)
+                BFLog(message: "转 WAV用时\( Date().timeIntervalSince(beginRecordTime1))")
+                // 删除录制的pcm文件
+                do {
+                    try FileManager.default.removeItem(atPath: outfile)
+                    print("Success to remove recorder file. \(outfile)")
+                } catch {
+                    print("Failed to remove recorder file. \(outfile)")
+                }
+                
+                //2处理降噪
+                beginRecordTime1 = Date()
+                let noiseFilePath = wavFilePath.replacingOccurrences(of: ".wav", with: "_noise.wav")
+                BFLog(1, message: "降噪后地址:\(noiseFilePath) 原地址:\(wavFilePath)")
+                NXNoiseReduction().denoise(wavFilePath, outFile: noiseFilePath)
                 if let model = voiceModel {
-                    model.wavFilePath = outfile
+                    model.wavFilePath = noiseFilePath
                     model.duration = "\(duration)"
                     endRecordHandle?(model, nil)
                     
+                    BFLog(message: "降噪用时\( Date().timeIntervalSince(beginRecordTime1))")
+                    
+                }
+                // 删除临时 wav 文件
+                do {
+                    try FileManager.default.removeItem(atPath: wavFilePath)
+                    print("Success to remove recorder file. \(wavFilePath)")
+                } catch {
+                    print("Failed to remove recorder file. \(wavFilePath)")
                 }
                 
-                //            // 删除录制的原文件
-                //            do {
-                //                try FileManager.default.removeItem(atPath: outfile)
-                //                print("Success to remove recorder file. \(outfile)")
-                //            } catch {
-                //                print("Failed to remove recorder file. \(outfile)")
-                //            }
+
             }
             
         } else {
-            cShowHUB(superView: nil, msg: "说话时间太短")
+            cShowHUB(superView: nil, msg: "最短录制1秒")
             cancelRecordHandle?(voiceModel)
         }
     }
     
     public func eventCallback(_: BFRecorderManager, asrResult: String,audioFilePath:String) {
-        subtitleRecordHandle?(asrResult, audioFilePath)
+        //最后输出的文件是降噪后的
+        let noiseFilePath = audioFilePath.replacingOccurrences(of: ".pcm", with: "_noise.wav")
+        subtitleRecordHandle?(asrResult, noiseFilePath)
     }
 }

+ 26 - 14
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -88,8 +88,17 @@ public class BFRecordScreenController: BFBaseViewController {
     // MARK: 行为参数
 
     var movieIsProcessing = false
-    var events = [WithDrawModel]() // 行为记录,方便撤销
-    var isDragingProgressSlder: Bool = false // 是否在拖动进度条
+    
+    // 行为记录,方便撤销
+    var events = [WithDrawModel]() {
+        didSet {
+            withDrawBtn.isEnabled = (events.count != 0)
+        }
+    }
+    
+    // 是否在拖动进度条
+    var isDragingProgressSlder: Bool = false
+    
     var isStopAtRecordRange = -1
 
     // 保存识别出来的字幕信息,用于回放,和合成使用
@@ -181,7 +190,8 @@ public class BFRecordScreenController: BFBaseViewController {
         btn.setImage(imageInRecordScreenKit(by: "withdraw_h"), for: .highlighted)
         btn.setTitle("回退", for: .normal)
         btn.setTitleColor(.white, for: .normal)
-        btn.setTitleColor(.gray, for: .highlighted)
+        btn.setTitleColor(.lightGray, for: .disabled)
+        btn.isEnabled = false
         btn.titleLabel?.font = UIFont.systemFont(ofSize: 12)
         btn.contentVerticalAlignment = UIControl.ContentVerticalAlignment.center
         btn.addTarget(self, action: #selector(withdrawAction), for: .touchUpInside)
@@ -904,7 +914,7 @@ public class BFRecordScreenController: BFBaseViewController {
         collectionView.isScrollEnabled = true
 
         recorderManager?.stopRecord(isCancel: false)
-
+        changeWithDrawBtnLayout(true)
         if !avatarView.isHidden {
             avatarView.endRecord()
         }
@@ -956,7 +966,7 @@ public class BFRecordScreenController: BFBaseViewController {
                     }
                 }
             } else if action.type == 3 {
-                // 删除录音
+                // 恢复删除录音
                 var tuples = action.deletedVoices
                 if tuples != nil, tuples!.count > 0 {
                     tuples!.sort { tuple1, tuple2 in
@@ -977,6 +987,7 @@ public class BFRecordScreenController: BFBaseViewController {
                 if itemModels[currItemModelIndex].mediaType == .IMAGE {
                     itemModels[currItemModelIndex].materialDuraion = itemModels[currItemModelIndex].voiceStickers.last?.endTime ?? 0
                 }
+                
             } else {}
             events.removeLast()
 
@@ -997,6 +1008,7 @@ public class BFRecordScreenController: BFBaseViewController {
                 changeWithDrawBtnLayout(false)
             }
             searchStopAtRecordRange()
+            indirectionView?.resetAllSubViews(items: itemModels[currItemModelIndex].voiceStickers, totalDuration: itemModels[currItemModelIndex].materialDuraion)
         }
     }
 
@@ -1378,16 +1390,16 @@ public class BFRecordScreenController: BFBaseViewController {
 
         NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: assetPlayer?.currentItem, queue: .main) { [weak self] notify in
             BFLog(1, message: "AVPlayerItemDidPlayToEndTime = \(notify)")
-            if (self?.currItemModelIndex ?? 0) < ((self?.itemModels.count ?? 0) - 1) {
+//            if (self?.currItemModelIndex ?? 0) < ((self?.itemModels.count ?? 0) - 1) {
 //                self?.collectionView.setContentOffset(CGPoint(x: CGFloat((self?.currItemModelIndex ?? 0) + 1) * (self?.collectionView.frame.width ?? 0), y: 0), animated: true)
-            } else {
-                self?.isNormalPlaying = false
-                //            self?.assetPlayer?.seek(to: CMTime.zero)
-                //            self?.progressThumV.progress = 0
-                self?.isEndPlay = true
-                //            self?.currentPlayRecordIndex = -1
-                self?.recordBtn.isHidden = true
-            }
+//            } else {
+//            }
+            self?.isNormalPlaying = false
+            //            self?.assetPlayer?.seek(to: CMTime.zero)
+            //            self?.progressThumV.progress = 0
+            self?.isEndPlay = true
+            //            self?.currentPlayRecordIndex = -1
+            self?.recordBtn.isHidden = true
             if self?.isRecording ?? false {
                 self?.endRecord()
                 cShowHUB(superView: nil, msg: "此视频已录制到头了哦")