Ana içeriğe geç

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 DeviceANCAPI protokolüne uyar.
  • ANC denetimlerini etkinleştirmeden önce ancMode değeri .unknown olmamalı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.
Resmî beceriyi görüntüle

API Referansı

Framework

AIBuds.xcframework

İçe Aktarma

Swift
import AIBuds
import AIBudsFoundation

Protokol

Ayarlar ve komutlar DeviceANCAPI protokolüyle tanımlanır.

Swift
/// 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?
    )
}

Özellikler

ÖzellikTürAçıklama
ancModeANCModeGeçerli ANC modu.
ancGainNSNumber?Geçerli ANC kazancı; kullanılamıyorsa nil.
transparencyGainNSNumber?Geçerli şeffaflık kazancı; kullanılamıyorsa nil.
isAncFadeOnBool / BOOLANC kademeli geçişinin etkin olup olmadığı.

Örnek Yöntemleri

YöntemAmaç
setAncModeANC modunu değiştirir.
setAncGainANC kazancını değiştirir.
setTransparencyGainŞeffaflık kazancını değiştirir.
setAncFadeOnANC kademeli geçişini etkinleştirir veya devre dışı bırakır.

Parametreler

ParametreTürAçıklama
modeANCMode / AIBudsANCMode.normal, .anc veya .transparency. .unknown ayarlamayın.
ancGainInt / NSIntegerİstenen ANC kazancı. Güncel Demo 0...100 kullanır; genel SDK henüz evrensel bir aralık garanti etmez.
transparencyGainInt / NSIntegerİstenen şeffaflık kazancı. Güncel Demo 0...100 kullanır; genel SDK henüz evrensel bir aralık garanti etmez.
isOnBool / BOOLANC kademeli geçişinin etkinleştirilip etkinleştirilmeyeceği.
completionAIBudsCompletionHandler?İ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
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)")

ANC Modunu Değiştirme

Swift
device.setAncMode(.anc) { success, error in
    guard success else {
        print("Failed to change ANC mode: \(error?.localizedDescription ?? "Unknown error")")
        return
    }
    print("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
device.setAncGain(60, completion: nil)
device.setTransparencyGain(40, completion: nil)
device.setAncFadeOn(true, 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.