ANC (Active Noise Cancellation)
Connected device से मौजूदा ANC settings पढ़ें और mode, gains या fade behavior बदलें।
आवश्यक शर्तें
- Device connected और ready हो।
- Device
DeviceANCAPIconform करता हो। - ANC controls enable करने से पहले
ancMode,.unknownन हो।
AI की सहायता से लागू करें
AI से बनाएँ
इस वर्कफ़्लो को AI से लागू करें
आधिकारिक “AIBuds नॉइज़ कंट्रोल कॉन्फ़िगर करें” स्किल से वर्कफ़्लो को अपने ऐप के अनुसार लागू करें।
https://docs-aibuds.github.io/hi/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>Protocol की घोषणा
Settings और commands DeviceANCAPI में defined हैं।
- 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उपलब्ध properties
| Property | Type | विवरण |
|---|---|---|
ancMode | ANCMode | मौजूदा ANC mode। |
ancGain | NSNumber? | मौजूदा ANC gain; unavailable होने पर nil। |
transparencyGain | NSNumber? | मौजूदा transparency gain; unavailable होने पर nil। |
isAncFadeOn | Bool / BOOL | ANC fade enabled है या नहीं। |
Instance methods
| Method | उपयोग |
|---|---|
setAncMode | ANC mode बदलें। |
setAncGain | ANC gain बदलें। |
setTransparencyGain | Transparency gain बदलें। |
setAncFadeOn | ANC fade enable या disable करें। |
उपलब्ध parameters
| Parameter | Type | विवरण |
|---|---|---|
mode | ANCMode / AIBudsANCMode | .normal, .anc या .transparency। .unknown set न करें। |
ancGain | Int / NSInteger | Desired ANC gain। मौजूदा Demo 0...100 उपयोग करता है; public SDK अभी universal range की गारंटी नहीं देता। |
transparencyGain | Int / NSInteger | Desired transparency gain। मौजूदा Demo 0...100 उपयोग करता है; public SDK अभी universal range की गारंटी नहीं देता। |
isOn | Bool / BOOL | ANC fade enable करना है या नहीं। |
completion | AIBudsCompletionHandler? | Optional completion callback। |
Methods सीधे कोई value return नहीं करते। उनके completion callback को success और optional 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 mode बदलें
- 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");
}];Gain और fade बदलें
नीचे की values मौजूदा SDK Demo के अनुसार हैं। SDK device-specific gain limits publish करे तो इन्हें फिर जाँचें।
- 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];Error handling
Command fail हो तो UI को device की मौजूदा values पर restore करें और उपलब्ध callback error दिखाएँ। Public API ANC-specific error codes define नहीं करती।