Skip to content

2. Recording, Realtime PCM & WAV Decoding ​

Control recording start/stop, set custom segment durations or 8-hex session IDs, insert RECORD_MARK anchors, and decode 0x00-prefixed 4:1 IMA ADPCM streams into 16 kHz mono WAV in the browser.

ReAI Recording Card SDK Documentation › Recording & Realtime Audio
SDK v0.0.9 (MIT)BLE 5 NUS (Text + 0x00 Binary)Core >= 0.3.0 · Session >= 0.3.8 · Duration >= 0.3.13

Audio Encoding Specification ​

  • Format: 16 kHz / 16-bit / mono PCM compressed via 4-bit IMA ADPCM (~8 KB/s).
  • Nibble Order: Low nibble (byte & 0x0f) is decoded first, followed by high nibble (byte >> 4).
  • Segment Continuity: Reset AdpcmDecoder only at segment start edges; never reset mid-recording.

Code Examples ​

javascript
await client.setRealtimeEnabled(true);
await client.startRecordingWithDuration(300);
const unsub = client.onAudio((chunk) => {
  console.log(`Decoded ${chunk.samples.length} PCM samples`);
});
await client.recordMark();
await client.stopRealtimeRecording();
unsub();
rust
use reai_card_sdk::{wav_bytes, SAMPLE_RATE_HZ};

let session = device.start_realtime_recording().await?;
let mut audio = session.subscribe();
let mut samples = Vec::new();
for _ in 0..150 {
    samples.extend_from_slice(&audio.recv().await?.samples);
}
session.stop().await?;
std::fs::write("realtime.wav", wav_bytes(&samples, SAMPLE_RATE_HZ))?;

Live Web Demo ​

Disconnected
Web Bluetooth is unavailable in this browser/context (requires Chrome/Edge on HTTPS or localhost). You can still test every API using the Virtual Card Simulator.
Idle
PCM 16 kHz / 16-bit mono: 0 samples (0.00s)
Wire Protocol Log (BLE NUS / HTTP)
Connect a real card or Virtual Card Simulator to inspect live protocol frames.

Downloadable Example ​

HTML + Audio / WAVExample 02 · Realtime Waveform Monitor & WAV Exporter

Includes a pure JS IMA ADPCM decoder, live Canvas waveform plot, segment duration input, RECORD_MARK, and 44-byte WAV export.

02-realtime-audio-wav.html

ReAI Recording Card Developer Documentation · MIT Open Hardware SDK · Partner Assets