@tensamin/audio 0.1.14 → 0.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.
Files changed (49) hide show
  1. package/README.md +48 -231
  2. package/dist/chunk-6BJ4XGSA.mjs +80 -0
  3. package/dist/chunk-AQ5RVY33.mjs +74 -0
  4. package/dist/chunk-IS37FHDN.mjs +33 -0
  5. package/dist/chunk-K4J3UUOR.mjs +178 -0
  6. package/dist/chunk-QNQK6QFB.mjs +71 -0
  7. package/dist/context/audio-context.d.mts +0 -24
  8. package/dist/context/audio-context.d.ts +0 -24
  9. package/dist/index.d.mts +2 -8
  10. package/dist/index.d.ts +2 -8
  11. package/dist/index.js +285 -680
  12. package/dist/index.mjs +8 -43
  13. package/dist/livekit/integration.d.mts +3 -7
  14. package/dist/livekit/integration.d.ts +3 -7
  15. package/dist/livekit/integration.js +280 -626
  16. package/dist/livekit/integration.mjs +7 -8
  17. package/dist/noise-suppression/deepfilternet-node.d.mts +12 -0
  18. package/dist/noise-suppression/deepfilternet-node.d.ts +12 -0
  19. package/dist/noise-suppression/deepfilternet-node.js +57 -0
  20. package/dist/noise-suppression/deepfilternet-node.mjs +6 -0
  21. package/dist/pipeline/audio-pipeline.d.mts +2 -2
  22. package/dist/pipeline/audio-pipeline.d.ts +2 -2
  23. package/dist/pipeline/audio-pipeline.js +219 -554
  24. package/dist/pipeline/audio-pipeline.mjs +4 -5
  25. package/dist/types.d.mts +42 -257
  26. package/dist/types.d.ts +42 -257
  27. package/dist/vad/vad-node.d.mts +7 -9
  28. package/dist/vad/vad-node.d.ts +7 -9
  29. package/dist/vad/vad-node.js +47 -156
  30. package/dist/vad/vad-node.mjs +3 -3
  31. package/dist/vad/vad-state.d.mts +9 -11
  32. package/dist/vad/vad-state.d.ts +9 -11
  33. package/dist/vad/vad-state.js +50 -79
  34. package/dist/vad/vad-state.mjs +3 -3
  35. package/package.json +21 -21
  36. package/dist/chunk-2G2JFHJY.mjs +0 -180
  37. package/dist/chunk-6F2HZUYO.mjs +0 -91
  38. package/dist/chunk-K4YLH73B.mjs +0 -103
  39. package/dist/chunk-R5M2DGAQ.mjs +0 -311
  40. package/dist/chunk-UFKIAMG3.mjs +0 -47
  41. package/dist/chunk-XO6B3D4A.mjs +0 -67
  42. package/dist/extensibility/plugins.d.mts +0 -9
  43. package/dist/extensibility/plugins.d.ts +0 -9
  44. package/dist/extensibility/plugins.js +0 -320
  45. package/dist/extensibility/plugins.mjs +0 -14
  46. package/dist/noise-suppression/rnnoise-node.d.mts +0 -10
  47. package/dist/noise-suppression/rnnoise-node.d.ts +0 -10
  48. package/dist/noise-suppression/rnnoise-node.js +0 -101
  49. package/dist/noise-suppression/rnnoise-node.mjs +0 -6
@@ -0,0 +1,71 @@
1
+ // src/vad/vad-node.ts
2
+ function createLevelDetectorWorkletCode(smoothing) {
3
+ return `
4
+ class LevelDetectorProcessor extends AudioWorkletProcessor {
5
+ constructor() {
6
+ super();
7
+ this.smoothed = 0;
8
+ this.smoothing = ${smoothing};
9
+ }
10
+
11
+ process(inputs) {
12
+ const input = inputs[0];
13
+ if (!input || input.length === 0) return true;
14
+ const channel = input[0];
15
+ if (!channel || channel.length === 0) return true;
16
+
17
+ let sum = 0;
18
+ for (let i = 0; i < channel.length; i++) {
19
+ const sample = channel[i];
20
+ sum += sample * sample;
21
+ }
22
+ const rms = Math.sqrt(sum / channel.length);
23
+ this.smoothed = this.smoothed * this.smoothing + rms * (1 - this.smoothing);
24
+ const levelDb = 20 * Math.log10(Math.max(1e-8, this.smoothed));
25
+ this.port.postMessage({ levelDb });
26
+ return true;
27
+ }
28
+ }
29
+
30
+ registerProcessor('level-detector-processor', LevelDetectorProcessor);
31
+ `;
32
+ }
33
+ async function createLevelDetectorNode(context, onLevel, options) {
34
+ const smoothing = options?.smoothing ?? 0.9;
35
+ const workletCode = createLevelDetectorWorkletCode(smoothing);
36
+ const blob = new Blob([workletCode], { type: "application/javascript" });
37
+ const url = URL.createObjectURL(blob);
38
+ try {
39
+ await context.audioWorklet.addModule(url);
40
+ } finally {
41
+ URL.revokeObjectURL(url);
42
+ }
43
+ const node = new AudioWorkletNode(context, "level-detector-processor", {
44
+ numberOfInputs: 1,
45
+ numberOfOutputs: 0
46
+ });
47
+ node.port.onmessage = (event) => {
48
+ const { levelDb } = event.data ?? {};
49
+ if (typeof levelDb === "number" && !Number.isNaN(levelDb)) {
50
+ onLevel(levelDb);
51
+ }
52
+ };
53
+ node.port.onmessageerror = (event) => {
54
+ console.error("Level detector port error", event);
55
+ };
56
+ return {
57
+ node,
58
+ dispose: () => {
59
+ try {
60
+ node.port.onmessage = null;
61
+ node.port.close();
62
+ } catch (error) {
63
+ console.error("Failed to dispose level detector node", error);
64
+ }
65
+ }
66
+ };
67
+ }
68
+
69
+ export {
70
+ createLevelDetectorNode
71
+ };
@@ -1,32 +1,8 @@
1
- /**
2
- * Manages a shared AudioContext for the application.
3
- */
4
- /**
5
- * Gets the shared AudioContext, creating it if necessary.
6
- * @param options Optional AudioContextOptions
7
- */
8
1
  declare function getAudioContext(options?: AudioContextOptions): AudioContext;
9
- /**
10
- * Registers a pipeline usage. Keeps track of active users.
11
- */
12
2
  declare function registerPipeline(): void;
13
- /**
14
- * Unregisters a pipeline usage.
15
- * Optionally closes the context if no pipelines are active (not implemented by default to avoid churn).
16
- */
17
3
  declare function unregisterPipeline(): void;
18
- /**
19
- * Resumes the shared AudioContext.
20
- * Should be called in response to a user gesture.
21
- */
22
4
  declare function resumeAudioContext(): Promise<void>;
23
- /**
24
- * Suspends the shared AudioContext.
25
- */
26
5
  declare function suspendAudioContext(): Promise<void>;
27
- /**
28
- * Closes the shared AudioContext and releases resources.
29
- */
30
6
  declare function closeAudioContext(): Promise<void>;
31
7
 
32
8
  export { closeAudioContext, getAudioContext, registerPipeline, resumeAudioContext, suspendAudioContext, unregisterPipeline };
@@ -1,32 +1,8 @@
1
- /**
2
- * Manages a shared AudioContext for the application.
3
- */
4
- /**
5
- * Gets the shared AudioContext, creating it if necessary.
6
- * @param options Optional AudioContextOptions
7
- */
8
1
  declare function getAudioContext(options?: AudioContextOptions): AudioContext;
9
- /**
10
- * Registers a pipeline usage. Keeps track of active users.
11
- */
12
2
  declare function registerPipeline(): void;
13
- /**
14
- * Unregisters a pipeline usage.
15
- * Optionally closes the context if no pipelines are active (not implemented by default to avoid churn).
16
- */
17
3
  declare function unregisterPipeline(): void;
18
- /**
19
- * Resumes the shared AudioContext.
20
- * Should be called in response to a user gesture.
21
- */
22
4
  declare function resumeAudioContext(): Promise<void>;
23
- /**
24
- * Suspends the shared AudioContext.
25
- */
26
5
  declare function suspendAudioContext(): Promise<void>;
27
- /**
28
- * Closes the shared AudioContext and releases resources.
29
- */
30
6
  declare function closeAudioContext(): Promise<void>;
31
7
 
32
8
  export { closeAudioContext, getAudioContext, registerPipeline, resumeAudioContext, suspendAudioContext, unregisterPipeline };
package/dist/index.d.mts CHANGED
@@ -1,10 +1,4 @@
1
- export { AudioPipelineEvents, AudioPipelineHandle, AudioProcessingConfig, NoiseSuppressionPlugin, VADPlugin, VADState } from './types.mjs';
2
- export { closeAudioContext, getAudioContext, registerPipeline, resumeAudioContext, suspendAudioContext, unregisterPipeline } from './context/audio-context.mjs';
3
- export { createAudioPipeline } from './pipeline/audio-pipeline.mjs';
4
- export { attachProcessingToTrack } from './livekit/integration.mjs';
5
- export { getNoiseSuppressionPlugin, getVADPlugin, registerNoiseSuppressionPlugin, registerVADPlugin } from './extensibility/plugins.mjs';
6
- export { RNNoisePlugin } from './noise-suppression/rnnoise-node.mjs';
7
- export { EnergyVADPlugin } from './vad/vad-node.mjs';
8
- export { VADStateMachine } from './vad/vad-state.mjs';
1
+ export { AudioPipelineHandle, LivekitSpeakingOptions, NoiseSuppressionConfig, OutputGainConfig, SpeakingController, SpeakingDetectionConfig, SpeakingEvents, SpeakingState } from './types.mjs';
2
+ export { attachSpeakingDetectionToTrack } from './livekit/integration.mjs';
9
3
  import 'mitt';
10
4
  import 'livekit-client';
package/dist/index.d.ts CHANGED
@@ -1,10 +1,4 @@
1
- export { AudioPipelineEvents, AudioPipelineHandle, AudioProcessingConfig, NoiseSuppressionPlugin, VADPlugin, VADState } from './types.js';
2
- export { closeAudioContext, getAudioContext, registerPipeline, resumeAudioContext, suspendAudioContext, unregisterPipeline } from './context/audio-context.js';
3
- export { createAudioPipeline } from './pipeline/audio-pipeline.js';
4
- export { attachProcessingToTrack } from './livekit/integration.js';
5
- export { getNoiseSuppressionPlugin, getVADPlugin, registerNoiseSuppressionPlugin, registerVADPlugin } from './extensibility/plugins.js';
6
- export { RNNoisePlugin } from './noise-suppression/rnnoise-node.js';
7
- export { EnergyVADPlugin } from './vad/vad-node.js';
8
- export { VADStateMachine } from './vad/vad-state.js';
1
+ export { AudioPipelineHandle, LivekitSpeakingOptions, NoiseSuppressionConfig, OutputGainConfig, SpeakingController, SpeakingDetectionConfig, SpeakingEvents, SpeakingState } from './types.js';
2
+ export { attachSpeakingDetectionToTrack } from './livekit/integration.js';
9
3
  import 'mitt';
10
4
  import 'livekit-client';