|
@@ -32,7 +32,7 @@ public class NXAudioRecorder {
|
|
|
/// 初始化录音器
|
|
|
/// - Parameter path: 保存的文件全路径,注意文件后缀一定要是 caf
|
|
|
/// - Throws: description
|
|
|
- public init(path: String) throws {
|
|
|
+ public init(path: String, setting:[String: Any]? = nil) throws {
|
|
|
// 1,判断目录文件夹是否存在
|
|
|
recordFilePath = path
|
|
|
BFLog(message: "recorder file path is \(String(describing: recordFilePath))")
|
|
@@ -40,15 +40,20 @@ public class NXAudioRecorder {
|
|
|
// 2,参数
|
|
|
let fileURL = URL(fileURLWithPath: recordFilePath)
|
|
|
// 注意设置参数 设置不对就无法录制
|
|
|
- let settings: [String: Any] = [
|
|
|
- AVFormatIDKey: kAudioFormatLinearPCM,
|
|
|
- AVSampleRateKey: 16000.0,
|
|
|
- AVNumberOfChannelsKey: 1,
|
|
|
- AVEncoderBitDepthHintKey: 16,
|
|
|
-// AVLinearPCMIsFloatKey:true, // 不要打开ios 13有杂音
|
|
|
- AVEncoderAudioQualityKey: AVAudioQuality.max.rawValue, // 录音质量
|
|
|
- ]
|
|
|
- recorder = try AVAudioRecorder(url: fileURL, settings: settings)
|
|
|
+
|
|
|
+ var settings = setting
|
|
|
+ if settings == nil {
|
|
|
+ settings = [
|
|
|
+ AVFormatIDKey: kAudioFormatLinearPCM,
|
|
|
+ AVSampleRateKey: 16000.0,
|
|
|
+ AVNumberOfChannelsKey: 1,
|
|
|
+ AVEncoderBitDepthHintKey: 16,
|
|
|
+ // AVLinearPCMIsFloatKey:true, // 不要打开ios 13有杂音
|
|
|
+ AVEncoderAudioQualityKey: AVAudioQuality.max.rawValue, // 录音质量
|
|
|
+ ]
|
|
|
+
|
|
|
+ }
|
|
|
+ recorder = try AVAudioRecorder(url: fileURL, settings: settings!)
|
|
|
recorder.isMeteringEnabled = true
|
|
|
recorder.delegate = delegateHandler
|
|
|
recorder.prepareToRecord()
|
|
@@ -91,11 +96,12 @@ public class NXAudioRecorder {
|
|
|
|
|
|
// 停止录制
|
|
|
public func stopRecord(_ closure: @escaping (_ isSuccess: Bool, _ url: String) -> Void) {
|
|
|
+ stopTimer()
|
|
|
+
|
|
|
if !recorder.isRecording {
|
|
|
BFLog(message: "不是录制状态")
|
|
|
}
|
|
|
|
|
|
- stopTimer()
|
|
|
|
|
|
delegateHandler.finishClosure = closure
|
|
|
|