본문으로 건너뛰기

액티브 노이즈 캔슬링

읽기 현재 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
import AIBuds
import AIBudsFoundation

프로토콜

settings 및 commands 입니다 defined by DeviceANCAPI.

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

속성

속성타입설명
ancModeANCMode현재 ANC mode.
ancGainNSNumber?현재 ANC gain, 또는 nil 때 사용할 수 없는.
transparencyGainNSNumber?현재 transparency gain, 또는 nil 때 사용할 수 없는.
isAncFadeOnBool / BOOLWhether ANC fade 입니다 enabled.

인스턴스 메서드

메서드용도
setAncModeChange ANC mode.
setAncGainChange ANC gain.
setTransparencyGainChange transparency gain.
setAncFadeOnEnable 또는 disable ANC fade.

매개변수

매개변수타입설명
modeANCMode / AIBudsANCMode.normal, .anc, 또는 .transparency. 하지 마세요 set .unknown.
ancGainInt / NSIntegerDesired ANC gain. 현재 Demo 사용합니다 0...100; public SDK 하지 않습니다 yet guarantee universal range.
transparencyGainInt / NSIntegerDesired transparency gain. 현재 Demo 사용합니다 0...100; public SDK 하지 않습니다 yet guarantee universal range.
isOnBool / BOOLWhether ANC fade 권장됩니다 be enabled.
completionAIBudsCompletionHandler?선택적 completion 콜백.

methods 반환 no value directly. Their completion 콜백 receives success 및 선택적 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 모드 변경

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

Change Gain 및 Fade

following values follow 현재 SDK Demo. Revisit them 때 SDK publishes device-specific gain limits.

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

오류 처리

만약 command fails, restore UI values currently exposed by 기기 및 surface 콜백 오류 때 사용 가능한. 공개 API 하지 않습니다 define ANC-specific 오류 codes.