मुख्य कंटेंट तक स्किप करें

ANC (Active Noise Cancellation)

Connected device से मौजूदा ANC settings पढ़ें और mode, gains या fade behavior बदलें।

आवश्यक शर्तें

  • Device connected और ready हो।
  • Device DeviceANCAPI conform करता हो।
  • 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
import AIBuds
import AIBudsFoundation

Protocol की घोषणा

Settings और commands DeviceANCAPI में defined हैं।

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

उपलब्ध properties

PropertyTypeविवरण
ancModeANCModeमौजूदा ANC mode।
ancGainNSNumber?मौजूदा ANC gain; unavailable होने पर nil
transparencyGainNSNumber?मौजूदा transparency gain; unavailable होने पर nil
isAncFadeOnBool / BOOLANC fade enabled है या नहीं।

Instance methods

Methodउपयोग
setAncModeANC mode बदलें।
setAncGainANC gain बदलें।
setTransparencyGainTransparency gain बदलें।
setAncFadeOnANC fade enable या disable करें।

उपलब्ध parameters

ParameterTypeविवरण
modeANCMode / AIBudsANCMode.normal, .anc या .transparency.unknown set न करें।
ancGainInt / NSIntegerDesired ANC gain। मौजूदा Demo 0...100 उपयोग करता है; public SDK अभी universal range की गारंटी नहीं देता।
transparencyGainInt / NSIntegerDesired transparency gain। मौजूदा Demo 0...100 उपयोग करता है; public SDK अभी universal range की गारंटी नहीं देता।
isOnBool / BOOLANC fade enable करना है या नहीं।
completionAIBudsCompletionHandler?Optional completion callback।

Methods सीधे कोई value return नहीं करते। उनके completion callback को success और optional NSError मिलता है।

उपयोग के उदाहरण

मौजूदा settings पढ़ें

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 mode बदलें

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")
}

Gain और fade बदलें

नीचे की values मौजूदा SDK Demo के अनुसार हैं। SDK device-specific gain limits publish करे तो इन्हें फिर जाँचें।

Swift
device.setAncGain(60, completion: nil)
device.setTransparencyGain(40, completion: nil)
device.setAncFadeOn(true, completion: nil)

Error handling

Command fail हो तो UI को device की मौजूदा values पर restore करें और उपलब्ध callback error दिखाएँ। Public API ANC-specific error codes define नहीं करती।