@absolutejs/voice 0.0.22-beta.611 → 0.0.22-beta.612

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.
Files changed (2) hide show
  1. package/dist/index.js +9 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -42001,26 +42001,29 @@ var createRegexSemanticTurnDetector = (options) => {
42001
42001
  };
42002
42002
  };
42003
42003
  // src/core/bargeInDetector.ts
42004
+ var VOICED_FLOOR = 0.02;
42004
42005
  var measureTurnAudio = (chunks, format) => {
42005
42006
  const channels = format.channels ?? 1;
42006
42007
  const sampleRate = format.sampleRateHz ?? 16000;
42007
42008
  let sumSquares = 0;
42008
- let sampleCount = 0;
42009
+ let voicedSamples = 0;
42009
42010
  for (const chunk of chunks) {
42010
42011
  const usableBytes = chunk.byteLength - chunk.byteLength % 2;
42011
42012
  const view = new DataView(chunk.buffer, chunk.byteOffset, usableBytes);
42012
42013
  for (let offset = 0;offset < usableBytes; offset += 2) {
42013
42014
  const sample = view.getInt16(offset, true) / 32768;
42014
- sumSquares += sample * sample;
42015
- sampleCount += 1;
42015
+ if (Math.abs(sample) >= VOICED_FLOOR) {
42016
+ sumSquares += sample * sample;
42017
+ voicedSamples += 1;
42018
+ }
42016
42019
  }
42017
42020
  }
42018
- if (sampleCount === 0) {
42021
+ if (voicedSamples === 0) {
42019
42022
  return { durationMs: 0, rms: 0 };
42020
42023
  }
42021
42024
  return {
42022
- durationMs: sampleCount / channels / sampleRate * 1000,
42023
- rms: Math.sqrt(sumSquares / sampleCount)
42025
+ durationMs: voicedSamples / channels / sampleRate * 1000,
42026
+ rms: Math.sqrt(sumSquares / voicedSamples)
42024
42027
  };
42025
42028
  };
42026
42029
  var createAcousticBargeInDetector = (options = {}) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/voice",
3
- "version": "0.0.22-beta.611",
3
+ "version": "0.0.22-beta.612",
4
4
  "description": "Voice primitives and Elysia plugin for AbsoluteJS",
5
5
  "repository": {
6
6
  "type": "git",