| Profile | Direction | Quality | Use case |
|---|---|---|---|
A2DP (Advanced Audio Distribution Profile) | Output only | High quality (44.1/48 kHz stereo) | Music, media playback, TTS |
HFP (Hands-Free Profile) | Bidirectional | Mono voice, 16 kHz or 8 kHz (negotiated by the phone and glasses) | Voice capture from the glasses microphone |
Use https://wearables.developer.meta.com/docs/develop/dat/microphones-and-speakers/, then use the Wearables MCP endpoint https://mcp.developer.meta.com/wearables to call search_dat_docs for current Device Access Toolkit microphone and speaker guidance. Inspect my audio code first, then make the smallest fix for the selected profile: A2DP for output or HFP for microphone input. Preserve the ordering constraints with Device Access Toolkit camera streaming, verify route selection, and run the relevant local checks.
Use https://wearables.developer.meta.com/docs/develop/dat/microphones-and-speakers/, then use the Wearables MCP endpoint https://mcp.developer.meta.com/wearables to call search_dat_docs for current Device Access Toolkit in-stream audio guidance. Inspect my streaming code first, then add the smallest working slice: set an audio codec on the stream configuration before starting the stream, consume audio frames alongside video, and align them using each frame's presentation timestamp. Pick the lowest sample rate my feature needs, handle the paused state as a gap rather than an end, keep per-frame work small, and release listeners during teardown.
| Sample rate | Typical use |
|---|---|
16,000 Hz | Speech and voice, including passing audio to a transcription service. |
44,100 Hz | General-purpose recording. |
48,000 Hz | Highest fidelity. |
audioStream alongside the video stream.import com.meta.wearable.dat.camera.types.AudioCodec
import com.meta.wearable.dat.camera.types.AudioSampleRate
import com.meta.wearable.dat.camera.types.StreamConfiguration
import com.meta.wearable.dat.camera.types.VideoQuality
val configuration =
StreamConfiguration(
audioCodec =
AudioCodec.PCM(
sampleRate = AudioSampleRate.RATE_16000,
numberOfChannels = 1,
),
videoQuality = VideoQuality.MEDIUM,
frameRate = 24
)
audioCodec unset, or setting it to null, streams video only.scope.launch {
stream.audioStream.collect { frame ->
// frame.buffer holds the PCM bytes; presentationTimeUs is in microseconds.
handleAudio(frame.buffer, frame.presentationTimeUs)
}
}
stream.start()
StreamConfiguration initializer that takes an audio codec, then listen on audioFramePublisher.import MWDATCamera
let configuration = StreamConfiguration(
videoCodec: .raw,
audioCodec: .pcm(sampleRate: .rate16000, numberOfChannels: 1),
resolution: .medium,
frameRate: 24
)
let audioToken = stream.audioFramePublisher.listen { frame in
// frame.pcmBuffer holds Float32 samples; presentationTimeStamp aligns with video.
handleAudio(frame.pcmBuffer, frame.presentationTimeStamp)
}
stream.start()
import android.content.Context
import android.media.AudioDeviceInfo
import android.media.AudioManager
import android.os.Build
private fun routeAudioToBluetooth(context: Context): Boolean {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
return false
}
val audioManager = context.getSystemService(AudioManager::class.java)
val bluetoothDevice =
audioManager.availableCommunicationDevices.firstOrNull { device ->
device.type == AudioDeviceInfo.TYPE_BLUETOOTH_SCO
} ?: return false
audioManager.mode = AudioManager.MODE_IN_COMMUNICATION
return audioManager.setCommunicationDevice(bluetoothDevice)
}
import AVFoundation let audioSession = AVAudioSession.sharedInstance() try audioSession.setCategory(.playback, mode: .default, options: []) try audioSession.setActive(true, options: .notifyOthersOnDeactivation)
AVAudioPlayer, AVSpeechSynthesizer, or any standard audio API to play audio, then verify the active route before assuming output is on the glasses.let player = try AVAudioPlayer(contentsOf: audioFileURL) player.play()
let hasA2DPOutput = audioSession.currentRoute.outputs.contains {
$0.portType == .bluetoothA2DP
}
.allowBluetoothHFP for microphone capture; A2DP output options do not provide microphone access. If your SDK only exposes the older .allowBluetooth option, use that option for HFP.import AVFoundation
// Request microphone permission
let granted = await withCheckedContinuation { continuation in
AVAudioApplication.requestRecordPermission { granted in
continuation.resume(returning: granted)
}
}
guard granted else { return }
// Configure the session for HFP
let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(.playAndRecord, mode: .default, options: [.allowBluetoothHFP])
try audioSession.setActive(true, options: .notifyOthersOnDeactivation)
if let hfpInput = audioSession.availableInputs?.first(where: { $0.portType == .bluetoothHFP }) {
try audioSession.setPreferredInput(hfpInput)
}
AVAudioEnginelet audioEngine = AVAudioEngine()
let inputNode = audioEngine.inputNode
let format = inputNode.outputFormat(forBus: 0)
inputNode.installTap(onBus: 0, bufferSize: 1024, format: format) { buffer, _ in
// Forward the buffer to your audio pipeline (e.g., LiveKit, a file writer, etc.)
handleAudioBuffer(buffer)
}
audioEngine.prepare()
try audioEngine.start()
AVAudioEngineConfigurationChange, then reinstall the tap with the new outputFormat(forBus: 0) and restart the engine.AVAudioEngine before starting it:let file = try AVAudioFile(forReading: audioFileURL) let player = AVAudioPlayerNode() audioEngine.attach(player) audioEngine.connect(player, to: audioEngine.mainMixerNode, format: file.processingFormat) player.scheduleFile(file, at: nil) player.play()
audioSession.currentRoute.outputs contains a .bluetoothHFP port before relying on playback through the glasses.// Allow the Bluetooth HFP route to settle
try await Task.sleep(nanoseconds: 2 * NSEC_PER_SEC)
// Verify HFP is actually routed
let hasHFPRoute = audioSession.currentRoute.inputs.contains { $0.portType == .bluetoothHFP }
guard hasHFPRoute else {
audioEngine.stop()
try audioSession.setActive(false, options: .notifyOthersOnDeactivation)
throw MyError.hfpRouteUnavailable
}
removeTap(onBus:) to stop receiving input buffers, then deactivate the session. If you need to return to A2DP playback, reconfigure the audio session with .playback category after deactivation.inputNode.removeTap(onBus: 0) audioEngine.stop() try audioSession.setActive(false, options: .notifyOthersOnDeactivation)