AudioRecorder.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // AudioRecorder.h
  3. // mask
  4. //
  5. // Created by 翟玉磊 on 2019/1/3.
  6. // Copyright © 2019 翟玉磊. All rights reserved.
  7. // 功能描述 封装声音录制与播放
  8. #import <Foundation/Foundation.h>
  9. NS_ASSUME_NONNULL_BEGIN
  10. typedef void(^DetectionVoiceBlock)(double lowPassResults, double currentTime);
  11. @interface AudioRecorder : NSObject
  12. #pragma mark - 文件操作
  13. /// 录音文件保存路径
  14. NSString *GetFilePathWithDate(void);
  15. /// 获取文件名(包含后缀,如:xxx.acc;不包含文件类型,如xxx)
  16. NSString *GetFileNameWithFilePath(NSString *filePath, BOOL hasFileType);
  17. /// 获取文件大小
  18. long long GetFileSizeWithFilePath(NSString *filePath);
  19. /// 删除文件
  20. void DeleteFileWithFilePath(NSString *filePath);
  21. #pragma mark - 录音
  22. /// 实例化单例
  23. + (AudioRecorder *)shareManager;
  24. #pragma mark - 音频处理-录音
  25. /// 开始录音
  26. - (void)audioRecorderStartWithFilePath:(NSString *)filePath;
  27. /// 停止录音
  28. - (void)audioRecorderStop;
  29. /// 录音时长
  30. - (NSTimeInterval)durationAudioRecorderWithFilePath:(NSString *)filePath;
  31. /// 音量回调以及当前录制时间
  32. @property (nonatomic, readwrite, copy) DetectionVoiceBlock detectionVoiceBlock;
  33. #pragma mark - 音频处理-播放/停止
  34. /// 音频开始播放或停止
  35. - (void)audioPlayWithFilePath:(NSString *)filePath;
  36. /// 音频播放停止
  37. - (void)audioStop;
  38. @property (nonatomic, assign) BOOL playing;
  39. /*
  40. * 播放完成回调
  41. */
  42. @property (nonatomic, copy) void (^playerFinished)();
  43. - (void)clear;
  44. @end
  45. NS_ASSUME_NONNULL_END