Aktif Gürültü Engelleme
Bağlı cihazın geçerli ANC ayarlarını okuyun; modunu, kazançlarını veya kademeli geçiş davranışını güncelleyin.
Ön Koşullar
- Cihaz bağlı ve hazırdır.
- Cihaz
DeviceANCAPIprotokolüne uyar. - ANC denetimlerini etkinleştirmeden önce
ancModedeğeri.unknownolmamalıdır.
AI desteğiyle uygulayın
AI ile geliştirin
Bu iş akışını AI ile uygulayın
Resmî “AIBuds Gürültü Kontrolünü Yapılandırma” becerisini kullanarak iş akışını uygulamanıza uyarlayın.
https://docs-aibuds.github.io/tr/skills/configure-aibuds-anc adresini okuyup yönergeleri izleyin. Bu beceriyle “AIBuds Gürültü Kontrolünü Yapılandırma” iş akışını iOS projesinde uygulayıp doğrulayın.API Referansı
Framework
AIBuds.xcframework
İçe Aktarma
- Swift
- Objective-C
import AIBuds
import AIBudsFoundation#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>Protokol
Ayarlar ve komutlar DeviceANCAPI protokolüyle tanımlanır.
- 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Özellikler
| Özellik | Tür | Açıklama |
|---|---|---|
ancMode | ANCMode | Geçerli ANC modu. |
ancGain | NSNumber? | Geçerli ANC kazancı; kullanılamıyorsa nil. |
transparencyGain | NSNumber? | Geçerli şeffaflık kazancı; kullanılamıyorsa nil. |
isAncFadeOn | Bool / BOOL | ANC kademeli geçişinin etkin olup olmadığı. |
Örnek Yöntemleri
| Yöntem | Amaç |
|---|---|
setAncMode | ANC modunu değiştirir. |
setAncGain | ANC kazancını değiştirir. |
setTransparencyGain | Şeffaflık kazancını değiştirir. |
setAncFadeOn | ANC kademeli geçişini etkinleştirir veya devre dışı bırakır. |
Parametreler
| Parametre | Tür | Açıklama |
|---|---|---|
mode | ANCMode / AIBudsANCMode | .normal, .anc veya .transparency. .unknown ayarlamayın. |
ancGain | Int / NSInteger | İstenen ANC kazancı. Güncel Demo 0...100 kullanır; genel SDK henüz evrensel bir aralık garanti etmez. |
transparencyGain | Int / NSInteger | İstenen şeffaflık kazancı. Güncel Demo 0...100 kullanır; genel SDK henüz evrensel bir aralık garanti etmez. |
isOn | Bool / BOOL | ANC kademeli geçişinin etkinleştirilip etkinleştirilmeyeceği. |
completion | AIBudsCompletionHandler? | İsteğe bağlı completion callback’i. |
Yöntemler doğrudan değer döndürmez. Completion callback’i success ve isteğe bağlı bir NSError alır.
Kullanım Örnekleri
Geçerli Ayarları Okuma
- 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 Modunu Değiştirme
- 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");
}];Kazancı ve Kademeli Geçişi Değiştirme
Aşağıdaki değerler güncel SDK Demo’sunu izler. SDK cihaza özgü kazanç sınırlarını yayımladığında bunları yeniden değerlendirin.
- 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];Hata Yönetimi
Komut başarısız olursa kullanıcı arayüzünü cihazın bildirdiği geçerli değerlere geri yükleyin ve varsa callback hatasını gösterin. Genel API, ANC’ye özgü hata kodları tanımlamaz.