@entros/pulse-sdk 1.1.0 → 1.2.0
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/README.md +6 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +26 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -477,7 +477,7 @@ function extractFormantRatios(samples, sampleRate, frameSize, hopSize) {
|
|
|
477
477
|
const numFrames = Math.floor((samples.length - frameSize) / hopSize) + 1;
|
|
478
478
|
for (let i = 0; i < numFrames; i++) {
|
|
479
479
|
const start = i * hopSize;
|
|
480
|
-
const frame = samples.
|
|
480
|
+
const frame = samples.subarray(start, start + frameSize);
|
|
481
481
|
const windowed = new Float32Array(frameSize);
|
|
482
482
|
for (let j = 0; j < frameSize; j++) {
|
|
483
483
|
windowed[j] = (frame[j] ?? 0) * (0.54 - 0.46 * Math.cos(2 * Math.PI * j / (frameSize - 1)));
|
|
@@ -538,7 +538,7 @@ async function detectF0Contour(samples, sampleRate) {
|
|
|
538
538
|
}
|
|
539
539
|
for (let i = 0; i < numFrames; i++) {
|
|
540
540
|
const start = i * hopSize;
|
|
541
|
-
const frame = samples.
|
|
541
|
+
const frame = samples.subarray(start, start + frameSize);
|
|
542
542
|
const pitch = detect(frame);
|
|
543
543
|
if (pitch && pitch > 50 && pitch < 600) {
|
|
544
544
|
f0.push(pitch);
|
|
@@ -629,7 +629,7 @@ function computeHNR(samples, sampleRate, f0Contour) {
|
|
|
629
629
|
const f0 = f0Contour[i];
|
|
630
630
|
if (f0 <= 0) continue;
|
|
631
631
|
const start = i * hopSize;
|
|
632
|
-
const frame = samples.
|
|
632
|
+
const frame = samples.subarray(start, start + frameSize);
|
|
633
633
|
const period = Math.round(sampleRate / f0);
|
|
634
634
|
if (period <= 0 || period >= frame.length) continue;
|
|
635
635
|
let num = 0;
|
|
@@ -656,11 +656,10 @@ async function computeLTAS(samples, sampleRate) {
|
|
|
656
656
|
const flatnesses = [];
|
|
657
657
|
const spreads = [];
|
|
658
658
|
const numFrames = Math.floor((samples.length - frameSize) / hopSize) + 1;
|
|
659
|
+
const paddedFrame = new Float32Array(frameSize);
|
|
659
660
|
for (let i = 0; i < numFrames; i++) {
|
|
660
661
|
const start = i * hopSize;
|
|
661
|
-
|
|
662
|
-
const paddedFrame = new Float32Array(frameSize);
|
|
663
|
-
paddedFrame.set(frame);
|
|
662
|
+
paddedFrame.set(samples.subarray(start, start + frameSize), 0);
|
|
664
663
|
const features = Meyda.extract(
|
|
665
664
|
["spectralCentroid", "spectralRolloff", "spectralFlatness", "spectralSpread"],
|
|
666
665
|
paddedFrame,
|
|
@@ -715,7 +714,15 @@ async function extractSpeakerFeaturesDetailed(audio) {
|
|
|
715
714
|
const abs = Math.abs(samples[i] ?? 0);
|
|
716
715
|
if (abs > peakAmp) peakAmp = abs;
|
|
717
716
|
}
|
|
718
|
-
|
|
717
|
+
let normalizedSamples;
|
|
718
|
+
if (peakAmp > 1e-6) {
|
|
719
|
+
normalizedSamples = new Float32Array(samples.length);
|
|
720
|
+
for (let i = 0; i < samples.length; i++) {
|
|
721
|
+
normalizedSamples[i] = samples[i] / peakAmp * 0.9;
|
|
722
|
+
}
|
|
723
|
+
} else {
|
|
724
|
+
normalizedSamples = samples;
|
|
725
|
+
}
|
|
719
726
|
const { f0, amplitudes: normalizedAmplitudes, periods } = await detectF0Contour(normalizedSamples, sampleRate);
|
|
720
727
|
const amplitudes = [];
|
|
721
728
|
for (let i = 0; i < numFrames; i++) {
|
|
@@ -1887,10 +1894,15 @@ async function extractFingerprintAndValidate(sensorData, config, walletAddress,
|
|
|
1887
1894
|
clearTimeout(validateTimer);
|
|
1888
1895
|
if (!validateResponse.ok) {
|
|
1889
1896
|
const errorBody = await validateResponse.json().catch(() => ({}));
|
|
1890
|
-
|
|
1897
|
+
const body = errorBody;
|
|
1898
|
+
const reason = typeof body.reason === "string" ? body.reason : void 0;
|
|
1899
|
+
sdkWarn(
|
|
1900
|
+
`[Entros SDK] Feature validation rejected by server${reason ? ` (reason: ${reason})` : ""}`
|
|
1901
|
+
);
|
|
1891
1902
|
return {
|
|
1892
1903
|
ok: false,
|
|
1893
|
-
error:
|
|
1904
|
+
error: body.error || "Feature validation failed",
|
|
1905
|
+
reason
|
|
1894
1906
|
};
|
|
1895
1907
|
}
|
|
1896
1908
|
} catch (err) {
|
|
@@ -1967,7 +1979,8 @@ async function processSensorData(sensorData, config, wallet, connection, onProgr
|
|
|
1967
1979
|
success: false,
|
|
1968
1980
|
commitment: new Uint8Array(32),
|
|
1969
1981
|
isFirstVerification: false,
|
|
1970
|
-
error: extraction.error
|
|
1982
|
+
error: extraction.error,
|
|
1983
|
+
reason: extraction.reason
|
|
1971
1984
|
};
|
|
1972
1985
|
}
|
|
1973
1986
|
const { fingerprint, tbh, features } = extraction;
|
|
@@ -2145,7 +2158,8 @@ async function processResetSensorData(sensorData, config, wallet, connection, on
|
|
|
2145
2158
|
success: false,
|
|
2146
2159
|
commitment: new Uint8Array(32),
|
|
2147
2160
|
isFirstVerification: true,
|
|
2148
|
-
error: extraction.error
|
|
2161
|
+
error: extraction.error,
|
|
2162
|
+
reason: extraction.reason
|
|
2149
2163
|
};
|
|
2150
2164
|
}
|
|
2151
2165
|
const { tbh } = extraction;
|
|
@@ -2421,7 +2435,7 @@ var PulseSession = class {
|
|
|
2421
2435
|
walletAddress
|
|
2422
2436
|
);
|
|
2423
2437
|
if (!extraction.ok) {
|
|
2424
|
-
return { validated: false, error: extraction.error };
|
|
2438
|
+
return { validated: false, error: extraction.error, reason: extraction.reason };
|
|
2425
2439
|
}
|
|
2426
2440
|
return { validated: true };
|
|
2427
2441
|
}
|