Files
keyboard/keyBoard/Class/AiTalk/VM/AudioCaptureManager.h

56 lines
1.5 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// AudioCaptureManager.h
// keyBoard
//
// Created by Mac on 2026/1/15.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/// 音频采集参数(固定值,便于端到端稳定)
/// Sample Rate: 16000 Hz
/// Channels: 1 (Mono)
/// Format: PCM Int16 (pcm_s16le)
/// Frame Duration: 20ms (320 samples, 640 bytes)
extern const double kAudioSampleRate; // 16000.0
extern const int kAudioChannels; // 1
extern const NSUInteger kAudioFrameDuration; // 20 (ms)
extern const NSUInteger kAudioFrameSamples; // 320 (16000 * 0.02)
extern const NSUInteger kAudioFrameBytes; // 640 (320 * 2)
/// 音频采集管理器代理
@protocol AudioCaptureManagerDelegate <NSObject>
@required
/// 输出 PCM 帧20ms / 640 bytes
/// @param pcmFrame 640 字节的 PCM Int16 数据
- (void)audioCaptureManagerDidOutputPCMFrame:(NSData *)pcmFrame;
@optional
/// 更新 RMS 值(用于波形显示)
/// @param rms 当前音量的 RMS 值 (0.0 - 1.0)
- (void)audioCaptureManagerDidUpdateRMS:(float)rms;
@end
/// 音频采集管理器
/// 使用 AVAudioEngine 采集麦克风音频,输出 20ms PCM 帧
@interface AudioCaptureManager : NSObject
@property(nonatomic, weak) id<AudioCaptureManagerDelegate> delegate;
/// 是否正在采集
@property(nonatomic, assign, readonly, getter=isCapturing) BOOL capturing;
/// 开始采集
/// @param error 错误信息
/// @return 是否启动成功
- (BOOL)startCapture:(NSError **)error;
/// 停止采集
- (void)stopCapture;
@end
NS_ASSUME_NONNULL_END