CXR-L(EN)
CXR-L(EN)
IntroductionQuick StartDevelopment Flow & State-MachineTerms and Abbreviations
Feature Development
Version HistoryAndroid
iOS
cxr-l-sdk · v1.0.1 · snapshot 2026-05-13· ↗ source
Audio
Android: Audio
Scenario
On an existing CXRLink (created from either the CustomView or CustomApp flow), start the glasses-side audio stream. The SDK delivers PCM chunks via IAudioStreamCbk.onAudioReceived. The Sample writes the data to a file, wraps it into a WAV (16 kHz, mono, 16-bit), and supports local playback and sharing.
Prerequisites
CXRLSampleApplication.sharedCxrLinkhas been assigned andconnecthas completed (seeAudioUsageViewModel.init: if null then_ready=false).- The glasses-side scene is built: using the Sample as an example, before entering this page from the Sample entry, you must complete
customViewOpenin the CustomView flow (customViewOpenedis true), or completeopenAppin the CustomApp flow (appOpenedis true). You must not callstartAudioStreamwhen only the link is connected but the scene is not opened. - The Intent may carry
CONSTANT.EXTRA_ENTRY_TYPEascustomVieworcustomApp. In the Sample it is only used for UI copy differences (does not affect thestartAudioStreamcall itself).
Key APIs
| Method | Description |
|---|---|
setCXRAudioCbk(IAudioStreamCbk) | Register the audio stream callback (can be separate from setCXRLinkCbk). |
startAudioStream(codecType: Int) | The Sample uses codecType = 1. Returns Boolean indicating whether the request is initiated (final status follows logs/callbacks). |
stopAudioStream() | Stop capture; the Sample calls it in stopAudio and release. |
Callbacks (IAudioStreamCbk)
| Callback | Description |
|---|---|
onAudioReceived(data, offset, length) | PCM segment. The Sample bounds-checks offset/length before writing to FileOutputStream. |
onAudioStreamStateChanged(started: Boolean) | Stream state changes. |
onAudioError(code, info?) | Stops and prompts on error. |
PCM to WAV (Sample)
- Fixed sample rate 16000, channels 1, bit depth 16 (see
buildWavFromPcm). - On stop, duration is estimated by total bytes:
actualPcmSize / (16000 * 2)seconds.
Constraints
- Start streaming only when Bluetooth and CXR service are available; otherwise prompt the user to reconnect first (
_ready/_status). - For frequent disk writes, flush by chunks (the Sample flushes for the first few packets and every 20 packets). On finish, call
fd.sync()to best-effort persist data. - In
release()on page destroy, callstopAudioStream()to avoid background resource usage.
Sample reference paths
activities/audio/AudioUsageViewModel.ktactivities/audio/AudioUsageActivity.kt