openclaw/apps/macos/Sources/ObjCExceptionCatcher/ObjCExceptionCatcher.m
liji 46aa3205e4 feat(voice-wake): integrate ObjCExceptionCatcher for safe audio tap installation
- Added ObjCExceptionCatcher to handle Objective-C exceptions during AVAudioNode tap installation, preventing crashes when the audio subsystem is not fully initialized.
- Introduced a 0.5s delay before starting the voice wake runtime to ensure the audio subsystem is ready, reducing the risk of AVAudioEngine errors.
- Updated VoiceWakeRuntime to utilize the new exception catcher and implemented retry logic for starting the runtime with exponential backoff.

This enhances the stability of the voice wake feature during app launch.
2026-01-27 16:40:59 +08:00

21 lines
775 B
Objective-C

#import "include/ObjCExceptionCatcher.h"
BOOL CBTryInstallTap(AVAudioNode *node, AVAudioNodeBus bus, AVAudioFrameCount bufferSize,
AVAudioFormat * _Nullable format, AVAudioNodeTapBlock block, NSError **outError) {
@try {
[node installTapOnBus:bus bufferSize:bufferSize format:format block:block];
return YES;
}
@catch (NSException *exception) {
if (outError) {
*outError = [NSError errorWithDomain:@"ObjCExceptionCatcher"
code:1
userInfo:@{
NSLocalizedDescriptionKey: exception.reason ?: @"Unknown exception",
@"NSException": exception
}];
}
return NO;
}
}