@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/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +12 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/pulse.ts +2 -1
- package/src/sensor/audio.ts +9 -1
- package/src/sensor/types.ts +2 -0
package/dist/index.d.mts
CHANGED
|
@@ -50,6 +50,8 @@ interface CaptureOptions {
|
|
|
50
50
|
minDurationMs?: number;
|
|
51
51
|
/** Maximum capture duration in ms. Auto-stops if signal hasn't fired. Default: 60000 */
|
|
52
52
|
maxDurationMs?: number;
|
|
53
|
+
/** Called with RMS audio level (0-1) on each buffer during audio capture (~4x per second). */
|
|
54
|
+
onAudioLevel?: (rms: number) => void;
|
|
53
55
|
}
|
|
54
56
|
/** Stage of a capture session */
|
|
55
57
|
type CaptureStage = "audio" | "motion" | "touch";
|
|
@@ -118,7 +120,7 @@ declare class PulseSession {
|
|
|
118
120
|
private motionData;
|
|
119
121
|
private touchData;
|
|
120
122
|
constructor(config: ResolvedConfig, touchElement?: HTMLElement);
|
|
121
|
-
startAudio(): Promise<void>;
|
|
123
|
+
startAudio(onAudioLevel?: (rms: number) => void): Promise<void>;
|
|
122
124
|
stopAudio(): Promise<AudioCapture | null>;
|
|
123
125
|
skipAudio(): void;
|
|
124
126
|
startMotion(): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -50,6 +50,8 @@ interface CaptureOptions {
|
|
|
50
50
|
minDurationMs?: number;
|
|
51
51
|
/** Maximum capture duration in ms. Auto-stops if signal hasn't fired. Default: 60000 */
|
|
52
52
|
maxDurationMs?: number;
|
|
53
|
+
/** Called with RMS audio level (0-1) on each buffer during audio capture (~4x per second). */
|
|
54
|
+
onAudioLevel?: (rms: number) => void;
|
|
53
55
|
}
|
|
54
56
|
/** Stage of a capture session */
|
|
55
57
|
type CaptureStage = "audio" | "motion" | "touch";
|
|
@@ -118,7 +120,7 @@ declare class PulseSession {
|
|
|
118
120
|
private motionData;
|
|
119
121
|
private touchData;
|
|
120
122
|
constructor(config: ResolvedConfig, touchElement?: HTMLElement);
|
|
121
|
-
startAudio(): Promise<void>;
|
|
123
|
+
startAudio(onAudioLevel?: (rms: number) => void): Promise<void>;
|
|
122
124
|
stopAudio(): Promise<AudioCapture | null>;
|
|
123
125
|
skipAudio(): void;
|
|
124
126
|
startMotion(): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -13043,7 +13043,8 @@ async function captureAudio(options = {}) {
|
|
|
13043
13043
|
const {
|
|
13044
13044
|
signal,
|
|
13045
13045
|
minDurationMs = MIN_CAPTURE_MS,
|
|
13046
|
-
maxDurationMs = MAX_CAPTURE_MS
|
|
13046
|
+
maxDurationMs = MAX_CAPTURE_MS,
|
|
13047
|
+
onAudioLevel
|
|
13047
13048
|
} = options;
|
|
13048
13049
|
const stream = await navigator.mediaDevices.getUserMedia({
|
|
13049
13050
|
audio: {
|
|
@@ -13063,7 +13064,13 @@ async function captureAudio(options = {}) {
|
|
|
13063
13064
|
const bufferSize = 4096;
|
|
13064
13065
|
const processor = ctx.createScriptProcessor(bufferSize, 1, 1);
|
|
13065
13066
|
processor.onaudioprocess = (e2) => {
|
|
13066
|
-
|
|
13067
|
+
const data = e2.inputBuffer.getChannelData(0);
|
|
13068
|
+
chunks.push(new Float32Array(data));
|
|
13069
|
+
if (onAudioLevel) {
|
|
13070
|
+
let sum = 0;
|
|
13071
|
+
for (let i = 0; i < data.length; i++) sum += data[i] * data[i];
|
|
13072
|
+
onAudioLevel(Math.sqrt(sum / data.length));
|
|
13073
|
+
}
|
|
13067
13074
|
};
|
|
13068
13075
|
source.connect(processor);
|
|
13069
13076
|
processor.connect(ctx.destination);
|
|
@@ -13880,13 +13887,14 @@ var PulseSession = class {
|
|
|
13880
13887
|
this.touchElement = touchElement;
|
|
13881
13888
|
}
|
|
13882
13889
|
// --- Audio ---
|
|
13883
|
-
async startAudio() {
|
|
13890
|
+
async startAudio(onAudioLevel) {
|
|
13884
13891
|
if (this.audioStageState !== "idle")
|
|
13885
13892
|
throw new Error("Audio capture already started");
|
|
13886
13893
|
this.audioStageState = "capturing";
|
|
13887
13894
|
this.audioController = new AbortController();
|
|
13888
13895
|
this.audioPromise = captureAudio({
|
|
13889
|
-
signal: this.audioController.signal
|
|
13896
|
+
signal: this.audioController.signal,
|
|
13897
|
+
onAudioLevel
|
|
13890
13898
|
}).catch(() => null);
|
|
13891
13899
|
}
|
|
13892
13900
|
async stopAudio() {
|