|
@@ -25,9 +25,7 @@ class BFVoiceRecordManager: NSObject {
|
|
|
var NeoNuiDebugHandle: ((String?) -> Void)?
|
|
|
// 录音机 dubug信息
|
|
|
var AudioQueueRecoderDebugHandle: ((String?) -> Void)?
|
|
|
-
|
|
|
- // 开始录制时间
|
|
|
- var beginRecordTime: Date = Date()
|
|
|
+
|
|
|
// 音频文件模型
|
|
|
var voiceModel: PQVoiceModel?
|
|
|
// 停止是否为取消操作
|
|
@@ -60,10 +58,13 @@ class BFVoiceRecordManager: NSObject {
|
|
|
BFLog(message: "文件夹不存在 \(recorderFilePath)")
|
|
|
createDirectory(path: recorderFilePath)
|
|
|
}
|
|
|
+
|
|
|
recorderFilePath.append("recorder_\(Date().timeIntervalSince1970).pcm")
|
|
|
- beginRecordTime = Date()
|
|
|
- BFLog(1, message: "开始录音 \(recorderFilePath) 开始时间\(beginRecordTime)")
|
|
|
- voiceModel?.wavFilePath = recorderFilePath
|
|
|
+
|
|
|
+ let noiseFilePath = recorderFilePath.replacingOccurrences(of: ".pcm", with: "_noise.wav")
|
|
|
+ voiceModel?.wavFilePath = noiseFilePath
|
|
|
+
|
|
|
+ BFLog(1, message: "开始录音 \(recorderFilePath)")
|
|
|
audioRecorder?.startRecord(recorderFilePath)
|
|
|
}
|
|
|
|
|
@@ -92,10 +93,7 @@ extension BFVoiceRecordManager: BFRecorderManagerDelegate {
|
|
|
}
|
|
|
|
|
|
public func recorderDidStop(_ outfile: String) {
|
|
|
- let duration = Date().timeIntervalSince(beginRecordTime)
|
|
|
- BFLog(1, message: "开始录音结束时间\(Date()) 时长\(duration)")
|
|
|
- if duration > 1 {
|
|
|
- if mIsCancel {
|
|
|
+ if mIsCancel {
|
|
|
// 删除录制的原文件
|
|
|
deleteFile(outfile: outfile)
|
|
|
cancelRecordHandle?(nil)
|
|
@@ -115,7 +113,6 @@ extension BFVoiceRecordManager: BFRecorderManagerDelegate {
|
|
|
NXNoiseReduction().denoise(wavFilePath, outFile: noiseFilePath)
|
|
|
if let model = voiceModel {
|
|
|
model.wavFilePath = noiseFilePath
|
|
|
- model.duration = "\(duration)"
|
|
|
endRecordHandle?(model, nil)
|
|
|
|
|
|
BFLog(message: "降噪用时\(Date().timeIntervalSince(beginRecordTime1))")
|
|
@@ -123,16 +120,11 @@ extension BFVoiceRecordManager: BFRecorderManagerDelegate {
|
|
|
// 删除临时 wav 文件
|
|
|
deleteFile(outfile: wavFilePath)
|
|
|
}
|
|
|
-
|
|
|
- } else {
|
|
|
- cancelRecordHandle?(voiceModel)
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
// 其它逻辑写在上面 保证最后关开关。
|
|
|
isStoping = false
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/// 删除文件
|
|
|
/// - Parameter outfile: <#outfile description#>
|
|
|
public func deleteFile(outfile:String) {
|