액티브 노이즈 캔슬링
읽기 현재 ANC settings 에서 connected device 및 update its mode, gains, 또는 fade behavior.
사전 요구 사항
- 기기 입니다 connected 및 ready.
- 기기 conforms
DeviceANCAPI. ancMode입니다 아닌.unknown전에 enabling ANC controls.
AI를 활용해 구현
AI로 구현
AI로 이 워크플로 구현
공식 “AIBuds 노이즈 컨트롤 설정” 스킬을 사용해 앱에 맞게 구현하세요.
https://docs-aibuds.github.io/ko/skills/configure-aibuds-anc을 읽고 지침을 따르세요. 이 스킬로 “AIBuds 노이즈 컨트롤 설정”을 이 iOS 프로젝트에 구현하고 검증하세요.API Reference
Framework
AIBuds.xcframework
Import
- Swift
- Objective-C
import AIBuds
import AIBudsFoundation#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>프로토콜
settings 및 commands 입니다 defined by DeviceANCAPI.
- Swift
- Objective-C
/// The protocol for device API that supports Active Noise Cancellation (ANC).
protocol DeviceANCAPI: DeviceAPI {
/// The current Active Noise Cancellation (ANC) mode of the device.
var ancMode: ANCMode { get }
/// The current ANC gain value of the device.
var ancGain: NSNumber? { get }
/// The current transparency gain value of the device.
var transparencyGain: NSNumber? { get }
/// Indicates whether the ANC fade feature is currently enabled.
var isAncFadeOn: Bool { get }
/// Sets the Active Noise Cancellation (ANC) mode for the device.
/// - Parameters:
/// - mode: The desired ANC mode to apply.
/// - completion: A closure that is called when the operation completes.
/// - success: Indicates whether the operation completed successfully.
/// - error: An optional error object that provides details if the operation failed; `nil` if the operation succeeded.
func setAncMode(
_ mode: ANCMode,
completion: AIBudsCompletionHandler?
)
/// Sets the ANC gain value for the device.
/// - Parameters:
/// - ancGain: The desired ANC gain value to apply.
/// - completion: A closure that is called when the operation completes.
/// - success: Indicates whether the operation completed successfully.
/// - error: An optional error object that provides details if the operation failed; `nil` if the operation succeeded.
func setAncGain(
_ ancGain: Int,
completion: AIBudsCompletionHandler?
)
/// Sets the transparency gain value for the device.
/// - Parameters:
/// - transparencyGain: The desired transparency gain value to apply.
/// - completion: A closure that is called when the operation completes.
/// - success: Indicates whether the operation completed successfully.
/// - error: An optional error object that provides details if the operation failed; `nil` if the operation succeeded.
func setTransparencyGain(
_ transparencyGain: Int,
completion: AIBudsCompletionHandler?
)
/// Enables or disables the ANC fade feature for the device.
/// - Parameters:
/// - isOn: A Boolean value indicating whether to enable (`true`) or disable (`false`) the ANC fade feature.
/// - completion: A closure that is called when the operation completes.
/// - success: Indicates whether the operation completed successfully.
/// - error: An optional error object that provides details if the operation failed; `nil` if the operation succeeded.
func setAncFadeOn(
_ isOn: Bool,
completion: AIBudsCompletionHandler?
)
}/// The protocol for device API that supports Active Noise Cancellation (ANC).
@protocol AIBudsDeviceANCAPI <AIBudsDeviceAPI>
/// The current Active Noise Cancellation (ANC) mode of the device.
@property(nonatomic, readonly) enum AIBudsANCMode ancMode;
/// The current ANC gain value of the device.
@property(nonatomic, readonly, strong) NSNumber *_Nullable ancGain;
/// The current transparency gain value of the device.
@property(nonatomic, readonly, strong) NSNumber *_Nullable transparencyGain;
/// Indicates whether the ANC fade feature is currently enabled.
@property(nonatomic, readonly) BOOL isAncFadeOn;
/// Sets the Active Noise Cancellation (ANC) mode for the device.
/// - Parameters:
/// - mode: The desired ANC mode to apply.
/// - completion: A closure that is called when the operation completes.
/// - success: Indicates whether the operation completed successfully.
/// - error: An optional error object that provides details if the operation failed; `nil` if
/// the operation succeeded.
- (void)setAncMode:(enum AIBudsANCMode)mode
completion:(AIBudsCompletionHandler _Nullable)completion;
/// Sets the ANC gain value for the device.
/// - Parameters:
/// - ancGain: The desired ANC gain value to apply.
/// - completion: A closure that is called when the operation completes.
/// - success: Indicates whether the operation completed successfully.
/// - error: An optional error object that provides details if the operation failed; `nil` if
/// the operation succeeded.
- (void)setAncGain:(NSInteger)ancGain completion:(AIBudsCompletionHandler _Nullable)completion;
/// Sets the transparency gain value for the device.
/// - Parameters:
/// - transparencyGain: The desired transparency gain value to apply.
/// - completion: A closure that is called when the operation completes.
/// - success: Indicates whether the operation completed successfully.
/// - error: An optional error object that provides details if the operation failed; `nil` if
/// the operation succeeded.
- (void)setTransparencyGain:(NSInteger)transparencyGain
completion:(AIBudsCompletionHandler _Nullable)completion;
/// Enables or disables the ANC fade feature for the device.
/// - Parameters:
/// - isOn: A Boolean value indicating whether to enable (`true`) or disable (`false`) the ANC
/// fade feature.
/// - completion: A closure that is called when the operation completes.
/// - success: Indicates whether the operation completed successfully.
/// - error: An optional error object that provides details if the operation failed; `nil` if
/// the operation succeeded.
- (void)setAncFadeOn:(BOOL)isOn completion:(AIBudsCompletionHandler _Nullable)completion;
@end속성
| 속성 | 타입 | 설명 |
|---|---|---|
ancMode | ANCMode | 현재 ANC mode. |
ancGain | NSNumber? | 현재 ANC gain, 또는 nil 때 사용할 수 없는. |
transparencyGain | NSNumber? | 현재 transparency gain, 또는 nil 때 사용할 수 없는. |
isAncFadeOn | Bool / BOOL | Whether ANC fade 입니다 enabled. |
인스턴스 메서드
| 메서드 | 용도 |
|---|---|
setAncMode | Change ANC mode. |
setAncGain | Change ANC gain. |
setTransparencyGain | Change transparency gain. |
setAncFadeOn | Enable 또는 disable ANC fade. |
매개변수
| 매개변수 | 타입 | 설명 |
|---|---|---|
mode | ANCMode / AIBudsANCMode | .normal, .anc, 또는 .transparency. 하지 마세요 set .unknown. |
ancGain | Int / NSInteger | Desired ANC gain. 현재 Demo 사용합니다 0...100; public SDK 하지 않습니다 yet guarantee universal range. |
transparencyGain | Int / NSInteger | Desired transparency gain. 현재 Demo 사용합니다 0...100; public SDK 하지 않습니다 yet guarantee universal range. |
isOn | Bool / BOOL | Whether ANC fade 권장됩니다 be enabled. |
completion | AIBudsCompletionHandler? | 선택적 completion 콜백. |
methods 반환 no value directly. Their completion 콜백 receives success 및 선택적 NSError.
사용 예제
읽기 현재 Settings
- Swift
- Objective-C
import AIBuds
guard let device = device as? DeviceANCAPI,
device.ancMode != .unknown
else {
print("Device does not support ANC")
return
}
print("Mode: \(device.ancMode)")
print("ANC gain: \(device.ancGain?.intValue.description ?? "Unavailable")")
print("Transparency gain: \(device.transparencyGain?.intValue.description ?? "Unavailable")")
print("ANC fade: \(device.isAncFadeOn)")#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
id<AIBudsDeviceANCAPI> device = (id<AIBudsDeviceANCAPI>)self.device;
if (![device conformsToProtocol:@protocol(AIBudsDeviceANCAPI)] ||
device.ancMode == AIBudsANCModeUnknown) {
NSLog(@"Device does not support ANC");
return;
}
NSLog(@"Mode: %ld", (long)device.ancMode);
NSLog(@"ANC gain: %@", device.ancGain ?: @"Unavailable");
NSLog(@"Transparency gain: %@", device.transparencyGain ?: @"Unavailable");
NSLog(@"ANC fade: %@", device.isAncFadeOn ? @"On" : @"Off");ANC 모드 변경
- Swift
- Objective-C
device.setAncMode(.anc) { success, error in
guard success else {
print("Failed to change ANC mode: \(error?.localizedDescription ?? "Unknown error")")
return
}
print("ANC mode updated")
}[device setAncMode:AIBudsANCModeAnc
completion:^(BOOL success, NSError *_Nullable error) {
if (!success) {
NSLog(@"Failed to change ANC mode: %@", error.localizedDescription);
return;
}
NSLog(@"ANC mode updated");
}];Change Gain 및 Fade
following values follow 현재 SDK Demo. Revisit them 때 SDK publishes device-specific gain limits.
- Swift
- Objective-C
device.setAncGain(60, completion: nil)
device.setTransparencyGain(40, completion: nil)
device.setAncFadeOn(true, completion: nil)[device setAncGain:60 completion:nil];
[device setTransparencyGain:40 completion:nil];
[device setAncFadeOn:YES completion:nil];오류 처리
만약 command fails, restore UI values currently exposed by 기기 및 surface 콜백 오류 때 사용 가능한. 공개 API 하지 않습니다 define ANC-specific 오류 codes.