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

67 lines
1.7 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.

//
// AudioSessionManager.h
// keyBoard
//
// Created by Mac on 2026/1/15.
//
#import <AVFoundation/AVFoundation.h>
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/// 音频会话中断类型
typedef NS_ENUM(NSInteger, KBAudioSessionInterruptionType) {
KBAudioSessionInterruptionTypeBegan, // 中断开始(来电等)
KBAudioSessionInterruptionTypeEnded // 中断结束
};
/// 音频会话管理器代理
@protocol AudioSessionManagerDelegate <NSObject>
@optional
/// 音频会话被中断
- (void)audioSessionManagerDidInterrupt:(KBAudioSessionInterruptionType)type;
/// 音频路由发生变化
- (void)audioSessionManagerRouteDidChange;
/// 麦克风权限状态变化
- (void)audioSessionManagerMicrophonePermissionDenied;
@end
/// 音频会话管理器
/// 负责 AVAudioSession 配置、权限请求、中断处理
@interface AudioSessionManager : NSObject
@property(nonatomic, weak) id<AudioSessionManagerDelegate> delegate;
/// 单例
+ (instancetype)sharedManager;
/// 请求麦克风权限
/// @param completion 完成回调granted 表示是否获得权限
- (void)requestMicrophonePermission:(void (^)(BOOL granted))completion;
/// 检查麦克风权限状态
- (BOOL)hasMicrophonePermission;
/// 配置音频会话为对话模式(录音+播放)
/// @param error 错误信息
/// @return 是否配置成功
- (BOOL)configureForConversation:(NSError **)error;
/// 配置音频会话为仅播放模式
/// @param error 错误信息
/// @return 是否配置成功
- (BOOL)configureForPlayback:(NSError **)error;
/// 激活音频会话
/// @param error 错误信息
/// @return 是否激活成功
- (BOOL)activateSession:(NSError **)error;
/// 停用音频会话
- (void)deactivateSession;
@end
NS_ASSUME_NONNULL_END