loudness-worklet 1.4.2 → 1.4.3

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 CHANGED
@@ -1,9 +1,14 @@
1
1
  # Loudness Audio Worklet Processor
2
2
 
3
- A loudness meter for the `Web Audio API`, based on the [ITU-R BS.1770-5](https://www.itu.int/rec/R-REC-BS.1770) standard and implemented as an AudioWorkletProcessor, [try demo](https://lcweden.github.io/loudness-audio-worklet-processor/).
3
+ [![npm version](https://img.shields.io/npm/v/loudness-worklet.svg)](https://www.npmjs.com/package/loudness-worklet)
4
+ [![license](https://img.shields.io/github/license/lcweden/loudness-audio-worklet-processor.svg)](LICENSE)
5
+
6
+ A loudness meter for the `Web Audio API`, based on the [ITU-R BS.1770-5](https://www.itu.int/rec/R-REC-BS.1770) standard and implemented as an AudioWorkletProcessor.
4
7
 
5
8
  [![screenshot](https://github.com/lcweden/loudness-audio-worklet-processor/blob/main/public/screenshots/meter.png)](https://lcweden.github.io/loudness-audio-worklet-processor/)
6
9
 
10
+ <p align="center"><a href="https://lcweden.github.io/loudness-audio-worklet-processor/">Demo</a></p>
11
+
7
12
  ## Features
8
13
 
9
14
  - **Loudness Measurement**: Compliant with the **ITU-R BS.1770-5** standard.
@@ -13,6 +18,15 @@ A loudness meter for the `Web Audio API`, based on the [ITU-R BS.1770-5](https:/
13
18
 
14
19
  ## Installation
15
20
 
21
+ ### CDN
22
+
23
+ Import directly in your code:
24
+
25
+ ```javascript
26
+ const module = new URL("https://lcweden.github.io/loudness-audio-worklet-processor/loudness.worklet.js");
27
+ audioContext.audioWorklet.addModule(module);
28
+ ```
29
+
16
30
  ### Download
17
31
 
18
32
  1. Download the pre-built file: [loudness.worklet.js](https://lcweden.github.io/loudness-audio-worklet-processor/loudness.worklet.js).
@@ -22,13 +36,36 @@ A loudness meter for the `Web Audio API`, based on the [ITU-R BS.1770-5](https:/
22
36
  audioContext.audioWorklet.addModule("loudness.worklet.js");
23
37
  ```
24
38
 
25
- ### Import
39
+ ### NPM
26
40
 
27
- Import the `AudioWorkletProcessor` directly in your code:
41
+ Install via [npm](https://www.npmjs.com/package/loudness-worklet):
42
+
43
+ ```bash
44
+ npm install loudness-worklet
45
+ ```
46
+
47
+ Use helper functions to create and load the worklet:
28
48
 
29
49
  ```javascript
30
- const module = new URL("https://lcweden.github.io/loudness-audio-worklet-processor/loudness.worklet.js");
31
- audioContext.audioWorklet.addModule(module);
50
+ import { createLoudnessWorklet, LoudnessWorkletNode } from "loudness-worklet";
51
+
52
+ const worklet = await createLoudnessWorklet(audioContext, {
53
+ processorOptions: {
54
+ interval: 0.1,
55
+ capacity: 600
56
+ }
57
+ });
58
+
59
+ // or
60
+
61
+ await LoudnessWorkletNode.loadModule(audioContext);
62
+
63
+ const worklet = new LoudnessWorkletNode(audioContext, {
64
+ processorOptions: {
65
+ interval: 0.1,
66
+ capacity: 600
67
+ }
68
+ });
32
69
  ```
33
70
 
34
71
  ## Quick Start
@@ -41,29 +78,38 @@ This example shows the easiest way to get started with the Loudness Audio Workle
41
78
  <!doctype html>
42
79
  <html>
43
80
  <body>
81
+ <button>Share Screen</button>
44
82
  <pre></pre>
45
83
  <script>
84
+ const script = "https://lcweden.github.io/loudness-audio-worklet-processor/loudness.worklet.js";
85
+ const button = document.querySelector("button");
46
86
  const pre = document.querySelector("pre");
47
- navigator.mediaDevices.getDisplayMedia({ audio: true }).then((mediaStream) => {
48
- const audioTrack = mediaStream.getAudioTracks()[0];
49
- const { channelCount } = audioTrack.getSettings();
87
+
88
+ button.onclick = async () => {
89
+ // Get the screen stream with audio, for example a youtube tab
90
+ const mediaStream = await navigator.mediaDevices.getDisplayMedia({ audio: true });
50
91
  const context = new AudioContext();
51
- context.audioWorklet
52
- .addModule("https://lcweden.github.io/loudness-audio-worklet-processor/loudness.worklet.js")
53
- .then(() => {
54
- const source = new MediaStreamAudioSourceNode(context, { mediaStream });
55
- const worklet = new AudioWorkletNode(context, "loudness-processor", {
56
- processorOptions: {
57
- interval: 0.1,
58
- capacity: 600
59
- }
60
- });
61
-
62
- source.connect(worklet).port.onmessage = (event) => {
63
- pre.textContent = JSON.stringify(event.data, null, 2);
64
- };
65
- });
66
- });
92
+
93
+ // Load the loudness worklet processor
94
+ await context.audioWorklet.addModule(script);
95
+
96
+ // Create the audio node from the stream
97
+ const source = new MediaStreamAudioSourceNode(context, { mediaStream });
98
+ // Create the loudness worklet node
99
+ const worklet = new AudioWorkletNode(context, "loudness-processor", {
100
+ processorOptions: {
101
+ interval: 0.1,
102
+ capacity: 600 // it means 1 minute of history can be stored
103
+ }
104
+ });
105
+
106
+ worklet.port.onmessage = (event) => {
107
+ pre.textContent = JSON.stringify(event.data, null, 2);
108
+ };
109
+
110
+ // Connect the nodes
111
+ source.connect(worklet);
112
+ };
67
113
  </script>
68
114
  </body>
69
115
  </html>
@@ -85,6 +131,17 @@ await context.audioWorklet.addModule("loudness.worklet.js");
85
131
  const source = new AudioBufferSourceNode(context, { buffer: audioBuffer });
86
132
  const worklet = new AudioWorkletNode(context, "loudness-processor");
87
133
 
134
+ // Or using the helper function
135
+ //
136
+ // import { createLoudnessWorklet } from "loudness-worklet";
137
+ //
138
+ // const worklet = await createLoudnessWorklet(audioContext, {
139
+ // processorOptions: {
140
+ // interval: 0.1,
141
+ // capacity: 600
142
+ // }
143
+ // });
144
+
88
145
  worklet.port.onmessage = (event) => {
89
146
  console.log("Loudness Data:", event.data);
90
147
  };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,15 @@
1
+ interface LoudnessWorkletProcessorOptions {
2
+ numberOfInputs?: AudioWorkletNodeOptions["numberOfInputs"];
3
+ numberOfOutputs?: AudioWorkletNodeOptions["numberOfOutputs"];
4
+ outputChannelCount?: AudioWorkletNodeOptions["outputChannelCount"];
5
+ processorOptions?: {
6
+ interval?: number;
7
+ capacity?: number;
8
+ };
9
+ }
1
10
  declare class LoudnessWorkletNode extends AudioWorkletNode {
2
- constructor(context: BaseAudioContext, options?: AudioWorkletNodeOptions);
11
+ constructor(context: BaseAudioContext, options?: LoudnessWorkletProcessorOptions);
3
12
  static loadModule(context: BaseAudioContext): Promise<void>;
4
13
  }
5
- declare function createLoudnessWorklet(context: BaseAudioContext, options?: AudioWorkletNodeOptions): Promise<AudioWorkletNode>;
14
+ declare function createLoudnessWorklet(context: BaseAudioContext, options?: LoudnessWorkletProcessorOptions): Promise<AudioWorkletNode>;
6
15
  export { createLoudnessWorklet, LoudnessWorkletNode };
package/dist/index.js CHANGED
@@ -2,11 +2,11 @@ const i = `/**
2
2
  * A lightweight and efficient AudioWorklet for real-time loudness measurement in the browser, compliant with the ITU-R BS.1770-5 standard.
3
3
  *
4
4
  * @file loudness.worklet.js
5
- * @version 1.4.2
5
+ * @version 1.4.3
6
6
  * @author lcweden
7
7
  * @license MIT
8
8
  * @see git+https://github.com/lcweden/loudness-audio-worklet-processor.git
9
- * @date 2025-09-25T17:15:25.559Z
9
+ * @date 2025-09-25T18:58:20.105Z
10
10
  */\r
11
11
  \r
12
12
  class O {
@@ -372,17 +372,25 @@ class X extends AudioWorkletProcessor {
372
372
  }
373
373
  }
374
374
  registerProcessor("loudness-processor", X);
375
- `, e = URL.createObjectURL(new Blob([i], { type: "application/javascript" })), t = "loudness-processor";
375
+ `, t = "loudness-processor";
376
376
  class h extends AudioWorkletNode {
377
- constructor(n, r) {
378
- super(n, t, r);
377
+ constructor(n, e) {
378
+ super(n, t, e);
379
379
  }
380
380
  static async loadModule(n) {
381
- return await n.audioWorklet.addModule(e);
381
+ return r(n);
382
382
  }
383
383
  }
384
384
  async function o(s, n) {
385
- return await s.audioWorklet.addModule(e), new AudioWorkletNode(s, t, n);
385
+ return await r(s), new AudioWorkletNode(s, t, n);
386
+ }
387
+ async function r(s) {
388
+ const n = new Blob([i], { type: "application/javascript" }), e = URL.createObjectURL(n);
389
+ try {
390
+ await s.audioWorklet.addModule(e);
391
+ } finally {
392
+ URL.revokeObjectURL(e);
393
+ }
386
394
  }
387
395
  export {
388
396
  h as LoudnessWorkletNode,
package/package.json CHANGED
@@ -1,7 +1,26 @@
1
1
  {
2
2
  "name": "loudness-worklet",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "A lightweight and efficient AudioWorklet for real-time loudness measurement in the browser, compliant with the ITU-R BS.1770-5 standard.",
5
+ "keywords": [
6
+ "web-audio",
7
+ "web-audio-api",
8
+ "audio-meter",
9
+ "audio-worklet",
10
+ "loudness",
11
+ "loudness-meter",
12
+ "browser-audio",
13
+ "ebu-r128",
14
+ "itu-r-bs1770",
15
+ "audio-processing",
16
+ "audio-analysis",
17
+ "true-peak",
18
+ "lufs",
19
+ "lra",
20
+ "javascript",
21
+ "typescript",
22
+ "lightweight"
23
+ ],
5
24
  "type": "module",
6
25
  "module": "./dist/index.js",
7
26
  "types": "./dist/index.d.ts",