|
@@ -10,6 +10,8 @@ import BFMediaKit
|
|
import Foundation
|
|
import Foundation
|
|
|
|
|
|
class BFVoiceRecordManager: NSObject {
|
|
class BFVoiceRecordManager: NSObject {
|
|
|
|
+
|
|
|
|
+ let debugHeader:String = "debugHeaderManger"
|
|
// 录音相关
|
|
// 录音相关
|
|
var audioRecorder: BFRecorderManager?
|
|
var audioRecorder: BFRecorderManager?
|
|
// 录音结束回调
|
|
// 录音结束回调
|
|
@@ -45,18 +47,19 @@ class BFVoiceRecordManager: NSObject {
|
|
deinit{
|
|
deinit{
|
|
audioRecorder?.delegate = nil
|
|
audioRecorder?.delegate = nil
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/// 开始录音
|
|
/// 开始录音
|
|
func startRecord() {
|
|
func startRecord() {
|
|
- BFLog(2, message: "开始录音 \(Date().timeIntervalSince1970)")
|
|
|
|
|
|
+ BFLog(2, message: "\(debugHeader)开始录音::: \(Date().timeIntervalSince1970)")
|
|
if isStoping {
|
|
if isStoping {
|
|
- BFLog(2, message: "正在停止中,这次开始无效.")
|
|
|
|
|
|
+ AudioQueueRecoderDebugHandle?("正在停止中,这次开始无效.")
|
|
|
|
+ BFLog(2, message: "\(debugHeader)正在停止中,这次开始无效.")
|
|
return
|
|
return
|
|
}
|
|
}
|
|
var recorderFilePath = exportAudiosDirectory
|
|
var recorderFilePath = exportAudiosDirectory
|
|
|
|
|
|
if !directoryIsExists(dicPath: recorderFilePath) {
|
|
if !directoryIsExists(dicPath: recorderFilePath) {
|
|
- BFLog(message: "文件夹不存在 \(recorderFilePath)")
|
|
|
|
|
|
+ BFLog(message: "\(debugHeader)文件夹不存在 \(recorderFilePath)")
|
|
createDirectory(path: recorderFilePath)
|
|
createDirectory(path: recorderFilePath)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -65,7 +68,7 @@ class BFVoiceRecordManager: NSObject {
|
|
let noiseFilePath = recorderFilePath.replacingOccurrences(of: ".pcm", with: "_noise.wav")
|
|
let noiseFilePath = recorderFilePath.replacingOccurrences(of: ".pcm", with: "_noise.wav")
|
|
voiceModel?.wavFilePath = noiseFilePath
|
|
voiceModel?.wavFilePath = noiseFilePath
|
|
|
|
|
|
- BFLog(1, message: "开始录音 \(recorderFilePath)")
|
|
|
|
|
|
+ BFLog(1, message: "\(debugHeader)开始录音::: \(recorderFilePath)")
|
|
audioRecorder?.startRecord(recorderFilePath)
|
|
audioRecorder?.startRecord(recorderFilePath)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -76,11 +79,16 @@ class BFVoiceRecordManager: NSObject {
|
|
/// 停止录制
|
|
/// 停止录制
|
|
/// - Parameter isCancel: 是否为取消 ,取消操作会把录制的文件删除和字幕删除
|
|
/// - Parameter isCancel: 是否为取消 ,取消操作会把录制的文件删除和字幕删除
|
|
func stopRecord(isCancel: Bool) {
|
|
func stopRecord(isCancel: Bool) {
|
|
- BFLog(2, message: "结束录音 \(Date().timeIntervalSince1970)")
|
|
|
|
|
|
+ BFLog(2, message: "\(debugHeader)结束录音::: \(Date().timeIntervalSince1970)")
|
|
|
|
+
|
|
isStoping = true
|
|
isStoping = true
|
|
mIsCancel = isCancel
|
|
mIsCancel = isCancel
|
|
- audioRecorder?.stopRecord()
|
|
|
|
-
|
|
|
|
|
|
+ //停止录音机录音
|
|
|
|
+ audioRecorder?.voiceRecorder.stop(true)
|
|
|
|
+ //停止字幕服务
|
|
|
|
+ audioRecorder?.stopNui_dialog()
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -93,33 +101,33 @@ extension BFVoiceRecordManager: BFRecorderManagerDelegate {
|
|
}
|
|
}
|
|
|
|
|
|
public func recorderDidStop(_ outfile: String) {
|
|
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
|
|
isStoping = false
|