@entros/pulse-sdk 1.5.0 → 1.5.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.mjs CHANGED
@@ -508,6 +508,26 @@ function extractFormantRatios(samples, sampleRate, frameSize, hopSize) {
508
508
  return { f1f2, f2f3 };
509
509
  }
510
510
 
511
+ // src/yield.ts
512
+ function yieldToMainThread() {
513
+ return new Promise((resolve) => {
514
+ if (typeof MessageChannel !== "undefined") {
515
+ const channel = new MessageChannel();
516
+ channel.port1.onmessage = () => {
517
+ channel.port1.close();
518
+ resolve();
519
+ };
520
+ channel.port2.postMessage(null);
521
+ return;
522
+ }
523
+ if (typeof setTimeout !== "undefined") {
524
+ setTimeout(resolve, 0);
525
+ return;
526
+ }
527
+ resolve();
528
+ });
529
+ }
530
+
511
531
  // src/extraction/speaker.ts
512
532
  function getFrameSize(sampleRate) {
513
533
  const MIN_F0 = 50;
@@ -740,6 +760,7 @@ async function extractSpeakerFeaturesDetailed(audio) {
740
760
  normalizedSamples = samples;
741
761
  }
742
762
  const { f0, amplitudes: normalizedAmplitudes, periods } = await detectF0Contour(normalizedSamples, sampleRate);
763
+ await yieldToMainThread();
743
764
  const amplitudes = [];
744
765
  for (let i = 0; i < numFrames; i++) {
745
766
  const start = i * hopSize;
@@ -764,6 +785,7 @@ async function extractSpeakerFeaturesDetailed(audio) {
764
785
  const hnrStats = condense(hnrValues);
765
786
  const hnrEntropy = entropy(hnrValues);
766
787
  const hnrFeatures = [hnrStats.mean, hnrStats.variance, hnrStats.skewness, hnrStats.kurtosis, hnrEntropy];
788
+ await yieldToMainThread();
767
789
  const { f1f2, f2f3 } = extractFormantRatios(normalizedSamples, sampleRate, frameSize, hopSize);
768
790
  const f1f2Stats = condense(f1f2);
769
791
  const f2f3Stats = condense(f2f3);
@@ -777,6 +799,7 @@ async function extractSpeakerFeaturesDetailed(audio) {
777
799
  f2f3Stats.skewness,
778
800
  f2f3Stats.kurtosis
779
801
  ];
802
+ await yieldToMainThread();
780
803
  const ltasFeatures = await computeLTAS(samples, sampleRate);
781
804
  const voicingFeatures = [voicedRatio];
782
805
  const ampStats = condense(amplitudes);
@@ -4211,10 +4234,13 @@ async function extractFeatures(data) {
4211
4234
  const { features: audioFeatures, f0Contour } = await extractSpeakerFeaturesDetailed(
4212
4235
  data.audio
4213
4236
  );
4237
+ await yieldToMainThread();
4214
4238
  const hasMotion = data.motion.length >= MIN_MOTION_SAMPLES;
4215
4239
  const hasTouch = data.touch.length >= MIN_TOUCH_SAMPLES;
4216
4240
  const motionFeatures = hasMotion && hasTouch ? extractMouseDynamics(data.touch) : hasMotion ? extractMotionFeatures(data.motion) : extractMouseDynamics(data.touch);
4241
+ await yieldToMainThread();
4217
4242
  const touchFeatures = extractTouchFeatures(data.touch);
4243
+ await yieldToMainThread();
4218
4244
  const accelMagnitude = hasMotion && f0Contour.length > 0 ? extractAccelerationMagnitude(data.motion, f0Contour.length) : [];
4219
4245
  return {
4220
4246
  raw: fuseRawFeatures(audioFeatures, motionFeatures, touchFeatures),
@@ -4228,6 +4254,7 @@ var MIN_MOTION_SAMPLES = 10;
4228
4254
  var MIN_TOUCH_SAMPLES = 10;
4229
4255
  async function extractFingerprintAndValidate(sensorData, config, walletAddress, onProgress) {
4230
4256
  onProgress?.("Extracting features...");
4257
+ await yieldToMainThread();
4231
4258
  const {
4232
4259
  raw: features,
4233
4260
  normalized: normalizedFeatures,
@@ -4242,6 +4269,7 @@ async function extractFingerprintAndValidate(sensorData, config, walletAddress,
4242
4269
  const tbh = await generateTBH(fingerprint);
4243
4270
  let signedReceipt;
4244
4271
  onProgress?.("Validating...");
4272
+ await yieldToMainThread();
4245
4273
  if (config.relayerUrl && walletAddress) {
4246
4274
  try {
4247
4275
  const baseUrl = new URL(config.relayerUrl);