Support for MacOS 14 Airpods Mute API

Description

In MacOS Sonoma, Apple implemented API and added ability to mute mic in app using gesture on Airpods pro 2.

This feature requires support from app, so please implement this simple functionality callbacks

// Adopting AVAudioApplication into your App
import AVFAudio

// Get the started instance 
let instance = AVAudioApplication.shared

// Register for mute gesture notifications on Notification Center 
AVAudioApplication.inputMuteStateChangeNotification

// Key for mute state
AVAudioApplication.muteStateKey

// Updating AVAudioApplication’s mute state
instance.setInputMuted(...)

// Reading AVAudioApplication’s mute state
instance.isInputMuted


// Configure the Input Mute State Change handler (macOS only)
instance.setInputMuteStateChangeHandler { isMuted in
	//...
	return didSucceed
}

// Optional: let CoreAudio mute your input for you (macOS only)
// Define the Core Audio property
var inputeMutePropertyAddress = AudioObjectPropertyAddress(
	mSelector: kAudioHardwarePropertyProcessInputMute,
	mScope: kAudioObjectPropertyScopeInput,
	mElement:kAudioObjectPropertyElementMain)

// Enable this property when you want to mute your input
UInt32 isMuted = 1; // 1 = muted, 0 = unmuted
AudioObjectSetPropertyData(kAudioObjectSystemObject,
						   &inputeMutePropertyAddress,
						   0,
						   nil,
						   UInt32(MemoryLayout.size(ofValue: isMuted),
						   &isMuted)

1 Like