@iam-protocol/pulse-sdk 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iam-protocol/pulse-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Client-side SDK for IAM Protocol — sensor capture, TBH generation, ZK proof construction",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/pulse.ts CHANGED
@@ -189,13 +189,14 @@ export class PulseSession {
189
189
 
190
190
  // --- Audio ---
191
191
 
192
- async startAudio(): Promise<void> {
192
+ async startAudio(onAudioLevel?: (rms: number) => void): Promise<void> {
193
193
  if (this.audioStageState !== "idle")
194
194
  throw new Error("Audio capture already started");
195
195
  this.audioStageState = "capturing";
196
196
  this.audioController = new AbortController();
197
197
  this.audioPromise = captureAudio({
198
198
  signal: this.audioController.signal,
199
+ onAudioLevel,
199
200
  }).catch(() => null);
200
201
  }
201
202
 
@@ -19,6 +19,7 @@ export async function captureAudio(
19
19
  signal,
20
20
  minDurationMs = MIN_CAPTURE_MS,
21
21
  maxDurationMs = MAX_CAPTURE_MS,
22
+ onAudioLevel,
22
23
  } = options;
23
24
 
24
25
  const stream = await navigator.mediaDevices.getUserMedia({
@@ -42,7 +43,14 @@ export async function captureAudio(
42
43
  const processor = ctx.createScriptProcessor(bufferSize, 1, 1);
43
44
 
44
45
  processor.onaudioprocess = (e: AudioProcessingEvent) => {
45
- chunks.push(new Float32Array(e.inputBuffer.getChannelData(0)));
46
+ const data = e.inputBuffer.getChannelData(0);
47
+ chunks.push(new Float32Array(data));
48
+
49
+ if (onAudioLevel) {
50
+ let sum = 0;
51
+ for (let i = 0; i < data.length; i++) sum += data[i]! * data[i]!;
52
+ onAudioLevel(Math.sqrt(sum / data.length));
53
+ }
46
54
  };
47
55
 
48
56
  source.connect(processor);
@@ -34,6 +34,8 @@ export interface CaptureOptions {
34
34
  minDurationMs?: number;
35
35
  /** Maximum capture duration in ms. Auto-stops if signal hasn't fired. Default: 60000 */
36
36
  maxDurationMs?: number;
37
+ /** Called with RMS audio level (0-1) on each buffer during audio capture (~4x per second). */
38
+ onAudioLevel?: (rms: number) => void;
37
39
  }
38
40
 
39
41
  /** Stage of a capture session */