浏览代码

停止录音时 字幕和录音机分别停止

jsonwang 3 年之前
父节点
当前提交
03f8196985
共有 1 个文件被更改,包括 42 次插入34 次删除
  1. 42 34
      BFRecordScreenKit/Classes/BFVoiceRecordManager.swift

+ 42 - 34
BFRecordScreenKit/Classes/BFVoiceRecordManager.swift

@@ -10,6 +10,8 @@ import BFMediaKit
 import Foundation
 
 class BFVoiceRecordManager: NSObject {
+    
+    let debugHeader:String = "debugHeaderManger"
     // 录音相关
     var audioRecorder: BFRecorderManager?
     // 录音结束回调
@@ -45,18 +47,19 @@ class BFVoiceRecordManager: NSObject {
     deinit{
         audioRecorder?.delegate = nil
     }
-
+ 
     /// 开始录音
     func startRecord() {
-        BFLog(2, message: "开始录音 \(Date().timeIntervalSince1970)")
+        BFLog(2, message: "\(debugHeader)开始录音::: \(Date().timeIntervalSince1970)")
         if isStoping {
-            BFLog(2, message: "正在停止中,这次开始无效.")
+            AudioQueueRecoderDebugHandle?("正在停止中,这次开始无效.")
+            BFLog(2, message: "\(debugHeader)正在停止中,这次开始无效.")
             return
         }
         var recorderFilePath = exportAudiosDirectory
 
         if !directoryIsExists(dicPath: recorderFilePath) {
-            BFLog(message: "文件夹不存在 \(recorderFilePath)")
+            BFLog(message: "\(debugHeader)文件夹不存在 \(recorderFilePath)")
             createDirectory(path: recorderFilePath)
         }
         
@@ -65,7 +68,7 @@ class BFVoiceRecordManager: NSObject {
         let noiseFilePath = recorderFilePath.replacingOccurrences(of: ".pcm", with: "_noise.wav")
         voiceModel?.wavFilePath = noiseFilePath
 
-        BFLog(1, message: "开始录音 \(recorderFilePath)")
+        BFLog(1, message: "\(debugHeader)开始录音::: \(recorderFilePath)")
         audioRecorder?.startRecord(recorderFilePath)
     }
     
@@ -76,11 +79,16 @@ class BFVoiceRecordManager: NSObject {
     /// 停止录制
     /// - Parameter isCancel: 是否为取消 ,取消操作会把录制的文件删除和字幕删除
     func stopRecord(isCancel: Bool) {
-        BFLog(2, message: "结束录音 \(Date().timeIntervalSince1970)")
+        BFLog(2, message: "\(debugHeader)结束录音::: \(Date().timeIntervalSince1970)")
+
         isStoping = true
         mIsCancel = isCancel
-        audioRecorder?.stopRecord()
- 
+        //停止录音机录音
+        audioRecorder?.voiceRecorder.stop(true)
+        //停止字幕服务
+        audioRecorder?.stopNui_dialog()
+       
+
     }
 }
 
@@ -93,33 +101,33 @@ extension BFVoiceRecordManager: BFRecorderManagerDelegate {
     }
 
     public func recorderDidStop(_ outfile: String) {
-             if mIsCancel {
-                // 删除录制的原文件
-                deleteFile(outfile: outfile)
-                cancelRecordHandle?(nil)
-            } else {
-                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))")
-                // 删除录制的原文件
-                deleteFile(outfile: 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 = noiseFilePath
-                    endRecordHandle?(model, nil)
-
-                    BFLog(message: "降噪用时\(Date().timeIntervalSince(beginRecordTime1))")
-                }
-                // 删除临时 wav 文件
-                deleteFile(outfile: wavFilePath)
+        if mIsCancel {
+            // 删除录制的原文件
+            deleteFile(outfile: outfile)
+            cancelRecordHandle?(nil)
+        } else {
+            var beginRecordTime1 = Date()
+
+            // 1转wav
+            let wavFilePath = outfile.replacingOccurrences(of: ".pcm", with: ".wav")
+            BFPcmToWaveTool().pcmToWav(inFileName: outfile, outFileName: wavFilePath)
+            BFLog(message: "\(debugHeader)转 WAV用时\(Date().timeIntervalSince(beginRecordTime1))")
+            // 删除录制的原文件
+            deleteFile(outfile: outfile)
+            // 2处理降噪
+            beginRecordTime1 = Date()
+            let noiseFilePath = wavFilePath.replacingOccurrences(of: ".wav", with: "_noise.wav")
+            BFLog(1, message: "\(debugHeader)降噪后地址:\(noiseFilePath) 原地址:\(wavFilePath)")
+            NXNoiseReduction().denoise(wavFilePath, outFile: noiseFilePath)
+            if let model = voiceModel {
+                model.wavFilePath = noiseFilePath
+                endRecordHandle?(model, nil)
+
+                BFLog(message: "\(debugHeader)降噪用时\(Date().timeIntervalSince(beginRecordTime1))")
             }
+            // 删除临时 wav 文件
+            deleteFile(outfile: wavFilePath)
+        }
  
         // 其它逻辑写在上面 保证最后关开关。
         isStoping = false