@tensamin/audio 0.2.7 → 0.2.9

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.
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  createAudioPipeline
3
- } from "./chunk-7DOV5ZIH.mjs";
3
+ } from "./chunk-GILJRVIL.mjs";
4
4
  import {
5
5
  createRemoteAudioMonitor
6
- } from "./chunk-47YTMONE.mjs";
6
+ } from "./chunk-4MAPY6Z3.mjs";
7
7
 
8
8
  // src/livekit/integration.ts
9
9
  async function attachSpeakingDetectionToTrack(track, options = {}) {
@@ -21,30 +21,16 @@ async function attachSpeakingDetectionToTrack(track, options = {}) {
21
21
  const listeners = /* @__PURE__ */ new Set();
22
22
  let mutedByController = false;
23
23
  let currentState = pipeline.state;
24
- let gainNode = null;
25
- if (options.muteWhenSilent) {
26
- try {
27
- const audioContext = new AudioContext();
28
- const source = audioContext.createMediaStreamSource(
29
- new MediaStream([pipeline.processedTrack])
30
- );
31
- gainNode = audioContext.createGain();
32
- source.connect(gainNode);
33
- gainNode.connect(audioContext.destination);
34
- } catch (error) {
35
- console.error("Failed to create gain node for volume control", error);
36
- }
37
- }
38
24
  const speakingHandler = (state) => {
39
25
  currentState = state;
40
26
  listeners.forEach((listener) => listener(state));
41
- if (options.muteWhenSilent && gainNode) {
42
- if (!state.speaking && gainNode.gain.value > 0) {
43
- gainNode.gain.value = 0;
27
+ if (options.muteWhenSilent) {
28
+ if (!state.speaking && !mutedByController) {
29
+ track.mute();
44
30
  mutedByController = true;
45
31
  }
46
32
  if (state.speaking && mutedByController) {
47
- gainNode.gain.value = 1;
33
+ track.unmute();
48
34
  mutedByController = false;
49
35
  }
50
36
  }
@@ -76,15 +62,9 @@ async function attachSpeakingDetectionToTrack(track, options = {}) {
76
62
  pipeline.events.off("speakingChange", speakingHandler);
77
63
  pipeline.events.off("error", errorHandler);
78
64
  listeners.clear();
79
- if (gainNode) {
80
- if (mutedByController && gainNode.gain.value === 0) {
81
- gainNode.gain.value = 1;
82
- mutedByController = false;
83
- }
84
- try {
85
- gainNode.disconnect();
86
- } catch (error) {
87
- }
65
+ if (mutedByController) {
66
+ track.unmute();
67
+ mutedByController = false;
88
68
  }
89
69
  pipeline.dispose();
90
70
  if (originalTrack.readyState === "live") {
@@ -3,11 +3,11 @@ import {
3
3
  } from "./chunk-QNQK6QFB.mjs";
4
4
  import {
5
5
  LevelBasedVAD
6
- } from "./chunk-XHU4WPFD.mjs";
6
+ } from "./chunk-ROWQ6JOD.mjs";
7
7
  import {
8
8
  DEFAULT_REMOTE_SPEAKING_OPTIONS,
9
9
  DEFAULT_SPEAKING_DETECTION_CONFIG
10
- } from "./chunk-FYX5A3OM.mjs";
10
+ } from "./chunk-GCPUFBJO.mjs";
11
11
  import {
12
12
  getAudioContext,
13
13
  registerPipeline,
@@ -1,16 +1,16 @@
1
1
  // src/defaults.ts
2
2
  var DEFAULT_SPEAKING_DETECTION_CONFIG = {
3
- minDb: -60,
4
- maxDb: -20,
3
+ minDb: -65,
4
+ maxDb: -15,
5
5
  speakOnRatio: 0.5,
6
6
  speakOffRatio: 0.3,
7
- hangoverMs: 500,
8
- attackMs: 100,
9
- releaseMs: 120
7
+ hangoverMs: 400,
8
+ attackMs: 70,
9
+ releaseMs: 100
10
10
  };
11
11
  var DEFAULT_NOISE_SUPPRESSION_CONFIG = {
12
12
  enabled: true,
13
- noiseReductionLevel: 60
13
+ noiseReductionLevel: 50
14
14
  };
15
15
  var DEFAULT_OUTPUT_GAIN_CONFIG = {
16
16
  speechGain: 1,
@@ -6,13 +6,13 @@ import {
6
6
  } from "./chunk-QNQK6QFB.mjs";
7
7
  import {
8
8
  LevelBasedVAD
9
- } from "./chunk-XHU4WPFD.mjs";
9
+ } from "./chunk-ROWQ6JOD.mjs";
10
10
  import {
11
11
  DEFAULT_LIVEKIT_SPEAKING_OPTIONS,
12
12
  DEFAULT_NOISE_SUPPRESSION_CONFIG,
13
13
  DEFAULT_OUTPUT_GAIN_CONFIG,
14
14
  DEFAULT_SPEAKING_DETECTION_CONFIG
15
- } from "./chunk-FYX5A3OM.mjs";
15
+ } from "./chunk-GCPUFBJO.mjs";
16
16
  import {
17
17
  getAudioContext,
18
18
  registerPipeline,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DEFAULT_SPEAKING_DETECTION_CONFIG
3
- } from "./chunk-FYX5A3OM.mjs";
3
+ } from "./chunk-GCPUFBJO.mjs";
4
4
 
5
5
  // src/vad/vad-state.ts
6
6
  var LevelBasedVAD = class {
package/dist/defaults.js CHANGED
@@ -28,17 +28,17 @@ __export(defaults_exports, {
28
28
  });
29
29
  module.exports = __toCommonJS(defaults_exports);
30
30
  var DEFAULT_SPEAKING_DETECTION_CONFIG = {
31
- minDb: -60,
32
- maxDb: -20,
31
+ minDb: -65,
32
+ maxDb: -15,
33
33
  speakOnRatio: 0.5,
34
34
  speakOffRatio: 0.3,
35
- hangoverMs: 500,
36
- attackMs: 100,
37
- releaseMs: 120
35
+ hangoverMs: 400,
36
+ attackMs: 70,
37
+ releaseMs: 100
38
38
  };
39
39
  var DEFAULT_NOISE_SUPPRESSION_CONFIG = {
40
40
  enabled: true,
41
- noiseReductionLevel: 60
41
+ noiseReductionLevel: 50
42
42
  };
43
43
  var DEFAULT_OUTPUT_GAIN_CONFIG = {
44
44
  speechGain: 1,
package/dist/defaults.mjs CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  DEFAULT_OUTPUT_GAIN_CONFIG,
5
5
  DEFAULT_REMOTE_SPEAKING_OPTIONS,
6
6
  DEFAULT_SPEAKING_DETECTION_CONFIG
7
- } from "./chunk-FYX5A3OM.mjs";
7
+ } from "./chunk-GCPUFBJO.mjs";
8
8
  export {
9
9
  DEFAULT_LIVEKIT_SPEAKING_OPTIONS,
10
10
  DEFAULT_NOISE_SUPPRESSION_CONFIG,
package/dist/index.js CHANGED
@@ -42,17 +42,17 @@ module.exports = __toCommonJS(index_exports);
42
42
 
43
43
  // src/defaults.ts
44
44
  var DEFAULT_SPEAKING_DETECTION_CONFIG = {
45
- minDb: -60,
46
- maxDb: -20,
45
+ minDb: -65,
46
+ maxDb: -15,
47
47
  speakOnRatio: 0.5,
48
48
  speakOffRatio: 0.3,
49
- hangoverMs: 500,
50
- attackMs: 100,
51
- releaseMs: 120
49
+ hangoverMs: 400,
50
+ attackMs: 70,
51
+ releaseMs: 100
52
52
  };
53
53
  var DEFAULT_NOISE_SUPPRESSION_CONFIG = {
54
54
  enabled: true,
55
- noiseReductionLevel: 60
55
+ noiseReductionLevel: 50
56
56
  };
57
57
  var DEFAULT_OUTPUT_GAIN_CONFIG = {
58
58
  speechGain: 1,
@@ -503,30 +503,16 @@ async function attachSpeakingDetectionToTrack(track, options = {}) {
503
503
  const listeners = /* @__PURE__ */ new Set();
504
504
  let mutedByController = false;
505
505
  let currentState = pipeline.state;
506
- let gainNode = null;
507
- if (options.muteWhenSilent) {
508
- try {
509
- const audioContext = new AudioContext();
510
- const source = audioContext.createMediaStreamSource(
511
- new MediaStream([pipeline.processedTrack])
512
- );
513
- gainNode = audioContext.createGain();
514
- source.connect(gainNode);
515
- gainNode.connect(audioContext.destination);
516
- } catch (error) {
517
- console.error("Failed to create gain node for volume control", error);
518
- }
519
- }
520
506
  const speakingHandler = (state) => {
521
507
  currentState = state;
522
508
  listeners.forEach((listener) => listener(state));
523
- if (options.muteWhenSilent && gainNode) {
524
- if (!state.speaking && gainNode.gain.value > 0) {
525
- gainNode.gain.value = 0;
509
+ if (options.muteWhenSilent) {
510
+ if (!state.speaking && !mutedByController) {
511
+ track.mute();
526
512
  mutedByController = true;
527
513
  }
528
514
  if (state.speaking && mutedByController) {
529
- gainNode.gain.value = 1;
515
+ track.unmute();
530
516
  mutedByController = false;
531
517
  }
532
518
  }
@@ -558,15 +544,9 @@ async function attachSpeakingDetectionToTrack(track, options = {}) {
558
544
  pipeline.events.off("speakingChange", speakingHandler);
559
545
  pipeline.events.off("error", errorHandler);
560
546
  listeners.clear();
561
- if (gainNode) {
562
- if (mutedByController && gainNode.gain.value === 0) {
563
- gainNode.gain.value = 1;
564
- mutedByController = false;
565
- }
566
- try {
567
- gainNode.disconnect();
568
- } catch (error) {
569
- }
547
+ if (mutedByController) {
548
+ track.unmute();
549
+ mutedByController = false;
570
550
  }
571
551
  pipeline.dispose();
572
552
  if (originalTrack.readyState === "live") {
package/dist/index.mjs CHANGED
@@ -2,19 +2,19 @@ import "./chunk-WBQAMGXK.mjs";
2
2
  import {
3
3
  attachSpeakingDetectionToRemoteTrack,
4
4
  attachSpeakingDetectionToTrack
5
- } from "./chunk-HCEWI3JP.mjs";
6
- import "./chunk-7DOV5ZIH.mjs";
5
+ } from "./chunk-326SVZPT.mjs";
6
+ import "./chunk-GILJRVIL.mjs";
7
7
  import "./chunk-IS37FHDN.mjs";
8
- import "./chunk-47YTMONE.mjs";
8
+ import "./chunk-4MAPY6Z3.mjs";
9
9
  import "./chunk-QNQK6QFB.mjs";
10
- import "./chunk-XHU4WPFD.mjs";
10
+ import "./chunk-ROWQ6JOD.mjs";
11
11
  import {
12
12
  DEFAULT_LIVEKIT_SPEAKING_OPTIONS,
13
13
  DEFAULT_NOISE_SUPPRESSION_CONFIG,
14
14
  DEFAULT_OUTPUT_GAIN_CONFIG,
15
15
  DEFAULT_REMOTE_SPEAKING_OPTIONS,
16
16
  DEFAULT_SPEAKING_DETECTION_CONFIG
17
- } from "./chunk-FYX5A3OM.mjs";
17
+ } from "./chunk-GCPUFBJO.mjs";
18
18
  import "./chunk-OZ7KMC4S.mjs";
19
19
  export {
20
20
  DEFAULT_LIVEKIT_SPEAKING_OPTIONS,
@@ -159,17 +159,17 @@ async function createLevelDetectorNode(context, onLevel, options) {
159
159
 
160
160
  // src/defaults.ts
161
161
  var DEFAULT_SPEAKING_DETECTION_CONFIG = {
162
- minDb: -60,
163
- maxDb: -20,
162
+ minDb: -65,
163
+ maxDb: -15,
164
164
  speakOnRatio: 0.5,
165
165
  speakOffRatio: 0.3,
166
- hangoverMs: 500,
167
- attackMs: 100,
168
- releaseMs: 120
166
+ hangoverMs: 400,
167
+ attackMs: 70,
168
+ releaseMs: 100
169
169
  };
170
170
  var DEFAULT_NOISE_SUPPRESSION_CONFIG = {
171
171
  enabled: true,
172
- noiseReductionLevel: 60
172
+ noiseReductionLevel: 50
173
173
  };
174
174
  var DEFAULT_OUTPUT_GAIN_CONFIG = {
175
175
  speechGain: 1,
@@ -498,30 +498,16 @@ async function attachSpeakingDetectionToTrack(track, options = {}) {
498
498
  const listeners = /* @__PURE__ */ new Set();
499
499
  let mutedByController = false;
500
500
  let currentState = pipeline.state;
501
- let gainNode = null;
502
- if (options.muteWhenSilent) {
503
- try {
504
- const audioContext = new AudioContext();
505
- const source = audioContext.createMediaStreamSource(
506
- new MediaStream([pipeline.processedTrack])
507
- );
508
- gainNode = audioContext.createGain();
509
- source.connect(gainNode);
510
- gainNode.connect(audioContext.destination);
511
- } catch (error) {
512
- console.error("Failed to create gain node for volume control", error);
513
- }
514
- }
515
501
  const speakingHandler = (state) => {
516
502
  currentState = state;
517
503
  listeners.forEach((listener) => listener(state));
518
- if (options.muteWhenSilent && gainNode) {
519
- if (!state.speaking && gainNode.gain.value > 0) {
520
- gainNode.gain.value = 0;
504
+ if (options.muteWhenSilent) {
505
+ if (!state.speaking && !mutedByController) {
506
+ track.mute();
521
507
  mutedByController = true;
522
508
  }
523
509
  if (state.speaking && mutedByController) {
524
- gainNode.gain.value = 1;
510
+ track.unmute();
525
511
  mutedByController = false;
526
512
  }
527
513
  }
@@ -553,15 +539,9 @@ async function attachSpeakingDetectionToTrack(track, options = {}) {
553
539
  pipeline.events.off("speakingChange", speakingHandler);
554
540
  pipeline.events.off("error", errorHandler);
555
541
  listeners.clear();
556
- if (gainNode) {
557
- if (mutedByController && gainNode.gain.value === 0) {
558
- gainNode.gain.value = 1;
559
- mutedByController = false;
560
- }
561
- try {
562
- gainNode.disconnect();
563
- } catch (error) {
564
- }
542
+ if (mutedByController) {
543
+ track.unmute();
544
+ mutedByController = false;
565
545
  }
566
546
  pipeline.dispose();
567
547
  if (originalTrack.readyState === "live") {
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  attachSpeakingDetectionToRemoteTrack,
3
3
  attachSpeakingDetectionToTrack
4
- } from "../chunk-HCEWI3JP.mjs";
5
- import "../chunk-7DOV5ZIH.mjs";
4
+ } from "../chunk-326SVZPT.mjs";
5
+ import "../chunk-GILJRVIL.mjs";
6
6
  import "../chunk-IS37FHDN.mjs";
7
- import "../chunk-47YTMONE.mjs";
7
+ import "../chunk-4MAPY6Z3.mjs";
8
8
  import "../chunk-QNQK6QFB.mjs";
9
- import "../chunk-XHU4WPFD.mjs";
10
- import "../chunk-FYX5A3OM.mjs";
9
+ import "../chunk-ROWQ6JOD.mjs";
10
+ import "../chunk-GCPUFBJO.mjs";
11
11
  import "../chunk-OZ7KMC4S.mjs";
12
12
  export {
13
13
  attachSpeakingDetectionToRemoteTrack,
@@ -156,17 +156,17 @@ async function createLevelDetectorNode(context, onLevel, options) {
156
156
 
157
157
  // src/defaults.ts
158
158
  var DEFAULT_SPEAKING_DETECTION_CONFIG = {
159
- minDb: -60,
160
- maxDb: -20,
159
+ minDb: -65,
160
+ maxDb: -15,
161
161
  speakOnRatio: 0.5,
162
162
  speakOffRatio: 0.3,
163
- hangoverMs: 500,
164
- attackMs: 100,
165
- releaseMs: 120
163
+ hangoverMs: 400,
164
+ attackMs: 70,
165
+ releaseMs: 100
166
166
  };
167
167
  var DEFAULT_NOISE_SUPPRESSION_CONFIG = {
168
168
  enabled: true,
169
- noiseReductionLevel: 60
169
+ noiseReductionLevel: 50
170
170
  };
171
171
  var DEFAULT_OUTPUT_GAIN_CONFIG = {
172
172
  speechGain: 1,
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  createAudioPipeline
3
- } from "../chunk-7DOV5ZIH.mjs";
3
+ } from "../chunk-GILJRVIL.mjs";
4
4
  import "../chunk-IS37FHDN.mjs";
5
5
  import "../chunk-QNQK6QFB.mjs";
6
- import "../chunk-XHU4WPFD.mjs";
7
- import "../chunk-FYX5A3OM.mjs";
6
+ import "../chunk-ROWQ6JOD.mjs";
7
+ import "../chunk-GCPUFBJO.mjs";
8
8
  import "../chunk-OZ7KMC4S.mjs";
9
9
  export {
10
10
  createAudioPipeline
@@ -126,13 +126,13 @@ async function createLevelDetectorNode(context, onLevel, options) {
126
126
 
127
127
  // src/defaults.ts
128
128
  var DEFAULT_SPEAKING_DETECTION_CONFIG = {
129
- minDb: -60,
130
- maxDb: -20,
129
+ minDb: -65,
130
+ maxDb: -15,
131
131
  speakOnRatio: 0.5,
132
132
  speakOffRatio: 0.3,
133
- hangoverMs: 500,
134
- attackMs: 100,
135
- releaseMs: 120
133
+ hangoverMs: 400,
134
+ attackMs: 70,
135
+ releaseMs: 100
136
136
  };
137
137
  var DEFAULT_REMOTE_SPEAKING_OPTIONS = {
138
138
  speaking: DEFAULT_SPEAKING_DETECTION_CONFIG
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  createRemoteAudioMonitor
3
- } from "../chunk-47YTMONE.mjs";
3
+ } from "../chunk-4MAPY6Z3.mjs";
4
4
  import "../chunk-QNQK6QFB.mjs";
5
- import "../chunk-XHU4WPFD.mjs";
6
- import "../chunk-FYX5A3OM.mjs";
5
+ import "../chunk-ROWQ6JOD.mjs";
6
+ import "../chunk-GCPUFBJO.mjs";
7
7
  import "../chunk-OZ7KMC4S.mjs";
8
8
  export {
9
9
  createRemoteAudioMonitor
@@ -26,13 +26,13 @@ module.exports = __toCommonJS(vad_state_exports);
26
26
 
27
27
  // src/defaults.ts
28
28
  var DEFAULT_SPEAKING_DETECTION_CONFIG = {
29
- minDb: -60,
30
- maxDb: -20,
29
+ minDb: -65,
30
+ maxDb: -15,
31
31
  speakOnRatio: 0.5,
32
32
  speakOffRatio: 0.3,
33
- hangoverMs: 500,
34
- attackMs: 100,
35
- releaseMs: 120
33
+ hangoverMs: 400,
34
+ attackMs: 70,
35
+ releaseMs: 100
36
36
  };
37
37
 
38
38
  // src/vad/vad-state.ts
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  LevelBasedVAD
3
- } from "../chunk-XHU4WPFD.mjs";
4
- import "../chunk-FYX5A3OM.mjs";
3
+ } from "../chunk-ROWQ6JOD.mjs";
4
+ import "../chunk-GCPUFBJO.mjs";
5
5
  export {
6
6
  LevelBasedVAD
7
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tensamin/audio",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "author": {
5
5
  "email": "aloisianer@proton.me",
6
6
  "name": "Alois"