Przeglądaj źródła

1,添加 debug 窗口,2,连续点击录制异常问题

jsonwang 3 lat temu
rodzic
commit
7f3836fbe5

+ 32 - 9
BFRecordScreenKit/Classes/BFVoiceRecordManager.swift

@@ -20,13 +20,20 @@ class BFVoiceRecordManager: NSObject {
     var recorderProgrossHandle: ((Float64?) -> Void)?
     //字幕的回调 参数1: 字幕数据 ,参数2 :对应的录音文件
     var subtitleRecordHandle: ((String?,String?) -> Void)?
+    
+    //字幕服务 dubug信息
+    var NeoNuiDebugHandle: ((String?) -> Void)?
+    //录音机 dubug信息
+    var AudioQueueRecoderDebugHandle: ((String?) -> Void)?
+    
     //开始录制时间
     var beginRecordTime: Date = Date()
     //音频文件模型
     var voiceModel: PQVoiceModel?
     //停止是否为取消操作
     var mIsCancel:Bool = false
-    
+    //是否正在停止中,从调用停止方法,到真正停止结束大约要300ms 左右。在这个期间内如果调用在调用了 start 开始时间被重置, 就会触发< 1s的逻辑。
+    var isStoping:Bool = false
     /// 初始化方法
     /// - Parameters:
     ///   - token: NLS token
@@ -36,10 +43,14 @@ class BFVoiceRecordManager: NSObject {
         audioRecorder = BFRecorderManager()
         audioRecorder?.delegate = self
     }
-    
-    
+     
     /// 开始录音
     func startRecord() {
+        
+        if(isStoping){
+            BFLog(2, message: "正在停止中,这次开始无效.")
+            return
+        }
         var recorderFilePath = exportAudiosDirectory
         
         if !directoryIsExists(dicPath: recorderFilePath) {
@@ -47,17 +58,16 @@ class BFVoiceRecordManager: NSObject {
             createDirectory(path: recorderFilePath)
         }
         recorderFilePath.append("recorder_\(Date().timeIntervalSince1970).pcm")
-        BFLog(1, message: "开始录音 \(recorderFilePath)")
-        
-        BFLog(1, message: "开始录制")
-        audioRecorder?.startRecord(recorderFilePath)
         beginRecordTime = Date()
+        BFLog(1, message: "开始录音 \(recorderFilePath)  开始时间\(beginRecordTime)")
+        audioRecorder?.startRecord(recorderFilePath)
+  
     }
     
     /// 停止录制
     /// - Parameter isCancel: 是否为取消 ,取消操作会把录制的文件删除和字幕删除
     func stopRecord(isCancel: Bool) {
-        
+        isStoping = true
         mIsCancel = isCancel
         audioRecorder?.stopRecord()
     }
@@ -72,6 +82,7 @@ extension BFVoiceRecordManager: BFRecorderManagerDelegate {
     
     public func recorderDidStop(_ outfile: String) {
         let duration = Date().timeIntervalSince(beginRecordTime)
+        BFLog(1, message: "开始录音结束时间\(Date()) 时长\(duration)")
         if duration > 1 {
             
             if(mIsCancel){
@@ -127,11 +138,23 @@ extension BFVoiceRecordManager: BFRecorderManagerDelegate {
             cShowHUB(superView: nil, msg: "最短录制1秒")
             cancelRecordHandle?(voiceModel)
         }
+        
+        //其它逻辑写在上面 保证最后关开关。
+        isStoping = false
     }
-    
+
+ 
     public func eventCallback(_: BFRecorderManager, asrResult: String,audioFilePath:String) {
         //最后输出的文件是降噪后的
         let noiseFilePath = audioFilePath.replacingOccurrences(of: ".pcm", with: "_noise.wav")
         subtitleRecordHandle?(asrResult, noiseFilePath)
     }
+    public func neoNuiDebugHandle(_ msg:String){
+        BFLog(2, message: "neoNuiDebugHandle :\(msg)")
+        NeoNuiDebugHandle?(msg)
+    }
+    public func audioQueueRecoderDebugHandle(_ msg:String){
+        BFLog(2, message: "audioQueueRecoderDebugHandle :\(msg)")
+        AudioQueueRecoderDebugHandle?(msg)
+    }
 }

+ 36 - 2
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -370,6 +370,26 @@ public class BFRecordScreenController: BFBaseViewController {
         }
         return collectionView
     }()
+    
+    //debug
+    lazy var neoNuiDebugLabel: UILabel = {
+        let neoNuiDebugLabel = UILabel.init(frame: CGRect.init(x: 0, y: 100, width: 200, height: 24))
+        neoNuiDebugLabel.backgroundColor = .black
+        neoNuiDebugLabel.textColor = .white
+        neoNuiDebugLabel.textAlignment = .left
+        return neoNuiDebugLabel
+
+    }()
+    lazy var audioQueueRecoderLabel: UILabel = {
+        let audioQueueRecoderLabel = UILabel.init(frame: CGRect.init(x: 0, y: 125, width: 200, height: 24))
+        audioQueueRecoderLabel.backgroundColor = .black
+        audioQueueRecoderLabel.textColor = .white
+        audioQueueRecoderLabel.textAlignment = .left
+        return audioQueueRecoderLabel
+
+    }()
+    
+    
 
     // MARK: - ----------------- 生命周期
 
@@ -413,7 +433,7 @@ public class BFRecordScreenController: BFBaseViewController {
 
         // 录音进度
         recorderManager?.recorderProgrossHandle = { [weak self] progress in
-            BFLog(1, message: "curr:录音进度--\(progress) \(self?.recordStartTime ?? 0) \(self?.isRecording ?? false)")
+            BFLog(1, message: "curr:录音进度--\(progress ?? 0.0) \(self?.recordStartTime ?? 0) \(self?.isRecording ?? false)")
             self?.drawProgressIndication(progress: progress ?? 0)
         }
 
@@ -549,7 +569,16 @@ public class BFRecordScreenController: BFBaseViewController {
             // 移除
             self?.indirectionView?.deleteItem(isCurrent: true)
         }
-
+         
+        recorderManager?.NeoNuiDebugHandle = { [weak self] msg in
+            self?.neoNuiDebugLabel.text = "录音机:\(msg ?? "")"
+        }
+        
+        recorderManager?.AudioQueueRecoderDebugHandle = { [weak self] msg in
+            self?.audioQueueRecoderLabel.text = "字幕服务:\(msg ?? "")"
+        }
+      
+        
         view.backgroundColor = .black
         view.addSubview(collectionView)
         //        playView = GPUImageView(frame: view.bounds)
@@ -613,6 +642,11 @@ public class BFRecordScreenController: BFBaseViewController {
         if !SWNetRequest.isNetReachabled() {
             cShowHUB(superView: view, msg: "网络不佳,字幕可能无法生成")
         }
+        
+        view.addSubview(neoNuiDebugLabel)
+        view.addSubview(audioQueueRecoderLabel)
+       
+       
     }
 
     @objc func editSubtitle() {