decibri 1.0.0 → 3.0.0-rc.2

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/LICENSE DELETED
@@ -1,191 +0,0 @@
1
-
2
- Apache License
3
- Version 2.0, January 2004
4
- http://www.apache.org/licenses/
5
-
6
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
-
8
- 1. Definitions.
9
-
10
- "License" shall mean the terms and conditions for use, reproduction,
11
- and distribution as defined by Sections 1 through 9 of this document.
12
-
13
- "Licensor" shall mean the copyright owner or entity authorized by
14
- the copyright owner that is granting the License.
15
-
16
- "Legal Entity" shall mean the union of the acting entity and all
17
- other entities that control, are controlled by, or are under common
18
- control with that entity. For the purposes of this definition,
19
- "control" means (i) the power, direct or indirect, to cause the
20
- direction or management of such entity, whether by contract or
21
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
- outstanding shares, or (iii) beneficial ownership of such entity.
23
-
24
- "You" (or "Your") shall mean an individual or Legal Entity
25
- exercising permissions granted by this License.
26
-
27
- "Source" form shall mean the preferred form for making modifications,
28
- including but not limited to software source code, documentation
29
- source, and configuration files.
30
-
31
- "Object" form shall mean any form resulting from mechanical
32
- transformation or translation of a Source form, including but
33
- not limited to compiled object code, generated documentation,
34
- and conversions to other media types.
35
-
36
- "Work" shall mean the work of authorship, whether in Source or
37
- Object form, made available under the License, as indicated by a
38
- copyright notice that is included in or attached to the work
39
- (an example is provided in the Appendix below).
40
-
41
- "Derivative Works" shall mean any work, whether in Source or Object
42
- form, that is based on (or derived from) the Work and for which the
43
- editorial revisions, annotations, elaborations, or other modifications
44
- represent, as a whole, an original work of authorship. For the purposes
45
- of this License, Derivative Works shall not include works that remain
46
- separable from, or merely link (or bind by name) to the interfaces of,
47
- the Work and Derivative Works thereof.
48
-
49
- "Contribution" shall mean any work of authorship, including
50
- the original version of the Work and any modifications or additions
51
- to that Work or Derivative Works thereof, that is intentionally
52
- submitted to the Licensor for inclusion in the Work by the copyright owner
53
- or by an individual or Legal Entity authorized to submit on behalf of
54
- the copyright owner. For the purposes of this definition, "submitted"
55
- means any form of electronic, verbal, or written communication sent
56
- to the Licensor or its representatives, including but not limited to
57
- communication on electronic mailing lists, source code control systems,
58
- and issue tracking systems that are managed by, or on behalf of, the
59
- Licensor for the purpose of discussing and improving the Work, but
60
- excluding communication that is conspicuously marked or otherwise
61
- designated in writing by the copyright owner as "Not a Contribution."
62
-
63
- "Contributor" shall mean Licensor and any individual or Legal Entity
64
- on behalf of whom a Contribution has been received by the Licensor and
65
- subsequently incorporated within the Work.
66
-
67
- 2. Grant of Copyright License. Subject to the terms and conditions of
68
- this License, each Contributor hereby grants to You a perpetual,
69
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
- copyright license to reproduce, prepare Derivative Works of,
71
- publicly display, publicly perform, sublicense, and distribute the
72
- Work and such Derivative Works in Source or Object form.
73
-
74
- 3. Grant of Patent License. Subject to the terms and conditions of
75
- this License, each Contributor hereby grants to You a perpetual,
76
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
- (except as stated in this section) patent license to make, have made,
78
- use, offer to sell, sell, import, and otherwise transfer the Work,
79
- where such license applies only to those patent claims licensable
80
- by such Contributor that are necessarily infringed by their
81
- Contribution(s) alone or by combination of their Contribution(s)
82
- with the Work to which such Contribution(s) was submitted. If You
83
- institute patent litigation against any entity (including a
84
- cross-claim or counterclaim in a lawsuit) alleging that the Work
85
- or a Contribution incorporated within the Work constitutes direct
86
- or contributory patent infringement, then any patent licenses
87
- granted to You under this License for that Work shall terminate
88
- as of the date such litigation is filed.
89
-
90
- 4. Redistribution. You may reproduce and distribute copies of the
91
- Work or Derivative Works thereof in any medium, with or without
92
- modifications, and in Source or Object form, provided that You
93
- meet the following conditions:
94
-
95
- (a) You must give any other recipients of the Work or
96
- Derivative Works a copy of this License; and
97
-
98
- (b) You must cause any modified files to carry prominent notices
99
- stating that You changed the files; and
100
-
101
- (c) You must retain, in the Source form of any Derivative Works
102
- that You distribute, all copyright, patent, trademark, and
103
- attribution notices from the Source form of the Work,
104
- excluding those notices that do not pertain to any part of
105
- the Derivative Works; and
106
-
107
- (d) If the Work includes a "NOTICE" text file as part of its
108
- distribution, then any Derivative Works that You distribute must
109
- include a readable copy of the attribution notices contained
110
- within such NOTICE file, excluding any notices that do not
111
- pertain to any part of the Derivative Works, in at least one
112
- of the following places: within a NOTICE text file distributed
113
- as part of the Derivative Works; within the Source form or
114
- documentation, if provided along with the Derivative Works; or,
115
- within a display generated by the Derivative Works, if and
116
- wherever such third-party notices normally appear. The contents
117
- of the NOTICE file are for informational purposes only and
118
- do not modify the License. You may add Your own attribution
119
- notices within Derivative Works that You distribute, alongside
120
- or as an addendum to the NOTICE text from the Work, provided
121
- that such additional attribution notices cannot be construed
122
- as modifying the License.
123
-
124
- You may add Your own copyright statement to Your modifications and
125
- may provide additional or different license terms and conditions
126
- for use, reproduction, or distribution of Your modifications, or
127
- for any such Derivative Works as a whole, provided Your use,
128
- reproduction, and distribution of the Work otherwise complies with
129
- the conditions stated in this License.
130
-
131
- 5. Submission of Contributions. Unless You explicitly state otherwise,
132
- any Contribution intentionally submitted for inclusion in the Work
133
- by You to the Licensor shall be under the terms and conditions of
134
- this License, without any additional terms or conditions.
135
- Notwithstanding the above, nothing herein shall supersede or modify
136
- the terms of any separate license agreement you may have executed
137
- with Licensor regarding such Contributions.
138
-
139
- 6. Trademarks. This License does not grant permission to use the trade
140
- names, trademarks, service marks, or product names of the Licensor,
141
- except as required for reasonable and customary use in describing the
142
- origin of the Work and reproducing the content of the NOTICE file.
143
-
144
- 7. Disclaimer of Warranty. Unless required by applicable law or
145
- agreed to in writing, Licensor provides the Work (and each
146
- Contributor provides its Contributions) on an "AS IS" BASIS,
147
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
- implied, including, without limitation, any warranties or conditions
149
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
- PARTICULAR PURPOSE. You are solely responsible for determining the
151
- appropriateness of using or redistributing the Work and assume any
152
- risks associated with Your exercise of permissions under this License.
153
-
154
- 8. Limitation of Liability. In no event and under no legal theory,
155
- whether in tort (including negligence), contract, or otherwise,
156
- unless required by applicable law (such as deliberate and grossly
157
- negligent acts) or agreed to in writing, shall any Contributor be
158
- liable to You for damages, including any direct, indirect, special,
159
- incidental, or consequential damages of any character arising as a
160
- result of this License or out of the use or inability to use the
161
- Work (including but not limited to damages for loss of goodwill,
162
- work stoppage, computer failure or malfunction, or any and all
163
- other commercial damages or losses), even if such Contributor
164
- has been advised of the possibility of such damages.
165
-
166
- 9. Accepting Warranty or Additional Liability. While redistributing
167
- the Work or Derivative Works thereof, You may choose to offer,
168
- and charge a fee for, acceptance of support, warranty, indemnity,
169
- or other liability obligations and/or rights consistent with this
170
- License. However, in accepting such obligations, You may act only
171
- on Your own behalf and on Your sole responsibility, not on behalf
172
- of any other Contributor, and only if You agree to indemnify,
173
- defend, and hold each Contributor harmless for any liability
174
- incurred by, or claims asserted against, such Contributor by reason
175
- of your accepting any such warranty or additional liability.
176
-
177
- END OF TERMS AND CONDITIONS
178
-
179
- Copyright 2026 Analytics in Motion
180
-
181
- Licensed under the Apache License, Version 2.0 (the "License");
182
- you may not use this file except in compliance with the License.
183
- You may obtain a copy of the License at
184
-
185
- http://www.apache.org/licenses/LICENSE-2.0
186
-
187
- Unless required by applicable law or agreed to in writing, software
188
- distributed under the License is distributed on an "AS IS" BASIS,
189
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
- See the License for the specific language governing permissions and
191
- limitations under the License.
package/README.md DELETED
@@ -1,294 +0,0 @@
1
- <!-- markdownlint-disable MD033 MD041 -->
2
- <div align="center">
3
- <img width="85" height="85" alt="Image" src="https://github.com/user-attachments/assets/2dce8788-02b4-4877-849c-274f776e063d" />
4
-
5
- # decibri
6
-
7
- Cross-platform microphone audio capture for Node.js.
8
-
9
- Pre-built binaries for Windows, macOS, and Linux. No build tools, no SoX, no system dependencies required.
10
-
11
- <!-- badges: start -->
12
- <table>
13
- <tr>
14
- <td><strong>Meta</strong></td>
15
- <td>
16
- <a href="https://www.npmjs.com/package/decibri"><img src="https://img.shields.io/npm/v/decibri" alt="npm version"></a>&nbsp;
17
- <a href="https://github.com/analyticsinmotion/decibri/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-Apache_2.0-blue.svg" alt="Apache 2.0 License"></a>&nbsp;
18
- <a href="https://decibri.dev"><img src="https://img.shields.io/badge/Website-decibri.dev-blue" alt="decibri.dev"></a>&nbsp;
19
- <a href="https://github.com/analyticsinmotion"><img src="https://github.com/user-attachments/assets/616c530f-cf2a-4f26-8f6c-7397be513847" alt="Analytics in Motion" width="137" height="20"></a>
20
- </td>
21
- </tr>
22
- <tr>
23
- <td><strong>Binaries</strong></td>
24
- <td>
25
- <a href="https://github.com/analyticsinmotion/decibri/actions/workflows/prebuild.yml"><img src="https://img.shields.io/github/actions/workflow/status/analyticsinmotion/decibri/prebuild.yml?job=Windows%20x64&label=Windows%20x64&logo=microsoft&logoColor=white" alt="Windows x64"></a>&nbsp;
26
- <a href="https://github.com/analyticsinmotion/decibri/actions/workflows/prebuild.yml"><img src="https://img.shields.io/github/actions/workflow/status/analyticsinmotion/decibri/prebuild.yml?job=macOS%20ARM64&label=macOS%20ARM64&logo=apple" alt="macOS ARM64"></a>&nbsp;
27
- <a href="https://github.com/analyticsinmotion/decibri/actions/workflows/prebuild.yml"><img src="https://img.shields.io/github/actions/workflow/status/analyticsinmotion/decibri/prebuild.yml?job=Linux%20x64&label=Linux%20x64&logo=linux&logoColor=white" alt="Linux x64"></a>&nbsp;
28
- <a href="https://github.com/analyticsinmotion/decibri/actions/workflows/prebuild.yml"><img src="https://img.shields.io/github/actions/workflow/status/analyticsinmotion/decibri/prebuild.yml?job=Linux%20ARM64&label=Linux%20ARM64&logo=linux&logoColor=white" alt="Linux ARM64"></a>
29
- </td>
30
- </tr>
31
- </table>
32
- <!-- badges: end -->
33
- </div>
34
-
35
- ---
36
-
37
- ## Installation
38
-
39
- ```bash
40
- npm install decibri
41
- ```
42
-
43
- Pre-compiled binaries for all supported platforms are bundled inside the package and loaded automatically by `node-gyp-build`. If no binary is available for your platform, it falls back to compiling from source (requires build tools and `libasound2-dev` on Linux).
44
-
45
- ---
46
-
47
- ## Usage
48
-
49
- ### Stream PCM audio from the default microphone
50
-
51
- ```javascript
52
- const Decibri = require('decibri');
53
-
54
- const mic = new Decibri();
55
-
56
- mic.on('data', (chunk) => {
57
- // chunk is a Buffer of 16-bit signed integer PCM samples (little-endian)
58
- // default: 16kHz, mono, 1600 frames per chunk (100ms)
59
- });
60
-
61
- mic.on('error', (err) => {
62
- console.error('Microphone error:', err);
63
- });
64
-
65
- // Stop after 10 seconds
66
- setTimeout(() => mic.stop(), 10000);
67
- ```
68
-
69
- ### Pipe to a file
70
-
71
- ```javascript
72
- const fs = require('fs');
73
- const Decibri = require('decibri');
74
-
75
- const mic = new Decibri({ sampleRate: 44100, channels: 2 });
76
- const out = fs.createWriteStream('capture.raw');
77
-
78
- mic.pipe(out);
79
-
80
- setTimeout(() => mic.stop(), 5000);
81
- ```
82
-
83
- ### Pipe to a speech engine
84
-
85
- ```javascript
86
- const Decibri = require('decibri');
87
-
88
- const mic = new Decibri({ sampleRate: 16000, channels: 1 });
89
-
90
- mic.on('data', (chunk) => {
91
- speechEngine.feed(chunk); // pass raw PCM directly
92
- });
93
- ```
94
-
95
- ### TypeScript
96
-
97
- TypeScript definitions are bundled. No `@types/` package needed.
98
-
99
- ```typescript
100
- import Decibri, { DeviceInfo, DecibriOptions } from 'decibri';
101
-
102
- const options: DecibriOptions = { sampleRate: 16000, channels: 1 };
103
- const mic = new Decibri(options);
104
-
105
- mic.on('data', (chunk: Buffer) => {
106
- // zero-copy Int16 view over the same memory
107
- const samples = new Int16Array(chunk.buffer, chunk.byteOffset, chunk.length / 2);
108
- });
109
-
110
- mic.on('backpressure', () => console.warn('Consumer too slow'));
111
-
112
- const devices: DeviceInfo[] = Decibri.devices();
113
- ```
114
-
115
- ---
116
-
117
- ## API
118
-
119
- ### `new Decibri(options?)`
120
-
121
- Creates a Readable stream that captures from the system default microphone.
122
-
123
- | Option | Type | Default | Description |
124
- | --- | --- | --- | --- |
125
- | `sampleRate` | number | `16000` | Samples per second (1000–384000) |
126
- | `channels` | number | `1` | Number of input channels (1–32) |
127
- | `framesPerBuffer` | number | `1600` | Frames per audio callback (64–65536) |
128
- | `device` | number \| string | system default | Device index from `Decibri.devices()` or case-insensitive name substring |
129
- | `format` | `'int16'` \| `'float32'` | `'int16'` | Sample encoding — 16-bit signed integer or 32-bit IEEE 754 float |
130
- | `vad` | boolean | `false` | Enable voice activity detection |
131
- | `vadThreshold` | number | `0.01` | RMS energy threshold for speech (0–1) |
132
- | `vadHoldoff` | number | `300` | Silence holdoff in ms before `'silence'` is emitted |
133
-
134
- Standard Node.js `Readable` stream options (e.g. `highWaterMark`) are also accepted.
135
-
136
- ### `mic.stop()`
137
-
138
- Stops microphone capture and ends the stream. Safe to call multiple times.
139
-
140
- ### Event: `'backpressure'`
141
-
142
- Emitted when `push()` returns `false`, meaning the stream's internal buffer is full and the consumer is reading too slowly. Because a microphone cannot be paused, audio chunks will continue to arrive. Callers should drain the stream or drop data to avoid unbounded memory growth.
143
-
144
- ### Event: `'speech'`
145
-
146
- Emitted when the RMS energy of an audio chunk crosses `vadThreshold`. Requires `vad: true`.
147
-
148
- ### Event: `'silence'`
149
-
150
- Emitted when audio stays below `vadThreshold` for `vadHoldoff` ms after a speech period. Requires `vad: true`.
151
-
152
- ### `mic.isOpen`
153
-
154
- `true` if the microphone is currently capturing.
155
-
156
- ### `Decibri.devices()`
157
-
158
- Returns an array of available input devices on the system.
159
-
160
- ```javascript
161
- const devices = Decibri.devices();
162
- // [
163
- // { index: 0, name: 'Built-in Microphone', maxInputChannels: 1, defaultSampleRate: 44100, isDefault: true },
164
- // ...
165
- // ]
166
- ```
167
-
168
- ### `Decibri.version()`
169
-
170
- Returns version information for decibri and the bundled PortAudio.
171
-
172
- ```javascript
173
- Decibri.version();
174
- // { decibri: '1.0.0', portaudio: 'PortAudio V19.7.0-devel...' }
175
- ```
176
-
177
- ---
178
-
179
- ## Examples
180
-
181
- Runnable examples are in [`examples/`](examples/).
182
-
183
- ### Capture to WAV file
184
-
185
- No external dependencies.
186
-
187
- ```bash
188
- node examples/wav-capture.js
189
- # writes capture.wav (5 seconds, 16 kHz mono)
190
- ```
191
-
192
- ### Stream to WebSocket
193
-
194
- The WebSocket examples require the `ws` package, which is **not** bundled with decibri. Install it before running:
195
-
196
- ```bash
197
- npm install ws
198
- ```
199
-
200
- Then in two terminals:
201
-
202
- ```bash
203
- # Terminal 1 — start receiver
204
- node examples/websocket-server.js
205
-
206
- # Terminal 2 — start streaming
207
- node examples/websocket-stream.js
208
- # streams raw PCM to ws://localhost:8080
209
- ```
210
-
211
- ---
212
-
213
- ## Audio format
214
-
215
- All audio is captured as **16-bit signed integer PCM, little-endian**. This is the raw format expected by most speech and wake-word engines (Vosk, sherpa-onnx, whisper.cpp, openWakeWord).
216
-
217
- Each `data` event emits a `Buffer` where every 2 bytes is one 16-bit sample:
218
-
219
- ```javascript
220
- mic.on('data', (chunk) => {
221
- const samples = new Int16Array(chunk.buffer, chunk.byteOffset, chunk.length / 2);
222
- // samples[0], samples[1], ...
223
- });
224
- ```
225
-
226
- ---
227
-
228
- ## Platform Support
229
-
230
- ### Pre-built binaries (zero setup)
231
-
232
- | Platform | Architecture | Audio Backend |
233
- | --- | --- | --- |
234
- | Windows 11 | x64 | WASAPI |
235
- | macOS (Apple Silicon) | arm64 | CoreAudio |
236
- | Linux | x64 | ALSA |
237
- | Linux | arm64 | ALSA |
238
-
239
- ### Source build fallback (requires build tools)
240
-
241
- | Platform | Requirements |
242
- | --- | --- |
243
- | macOS Intel (pre-2020) | Xcode CLI tools: `xcode-select --install` |
244
- | Windows ARM64 | Visual C++ Build Tools |
245
-
246
- ### Not supported
247
-
248
- | Platform | Reason |
249
- | --- | --- |
250
- | Windows 32-bit | N-API native addons require 64-bit |
251
-
252
- ---
253
-
254
- ## Building from source
255
-
256
- Requires Node.js >= 18, node-gyp, and platform build tools.
257
-
258
- **Linux:**
259
-
260
- ```bash
261
- sudo apt-get install -y build-essential libasound2-dev
262
- ```
263
-
264
- **macOS:**
265
-
266
- ```bash
267
- xcode-select --install
268
- ```
269
-
270
- **Windows:**
271
- Install [Visual C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/).
272
-
273
- Then:
274
-
275
- ```bash
276
- git clone --recurse-submodules https://github.com/analyticsinmotion/decibri.git
277
- cd decibri
278
- npm install
279
- npm run build
280
- ```
281
-
282
- ---
283
-
284
- ## How it works
285
-
286
- decibri wraps [PortAudio](http://www.portaudio.com/), the standard cross-platform audio I/O library, as a Node.js native addon using [N-API](https://nodejs.org/api/n-api.html). PortAudio is compiled from source and statically linked, so there is no system PortAudio dependency.
287
-
288
- The native addon opens the default input device, runs a PortAudio callback in an audio thread, and forwards PCM chunks to JavaScript via an N-API `ThreadSafeFunction`. The JavaScript layer wraps this in a standard Node.js `Readable` stream.
289
-
290
- ---
291
-
292
- ## License
293
-
294
- Apache-2.0 © [Analytics in Motion](https://github.com/analyticsinmotion)
package/binding.gyp DELETED
@@ -1,122 +0,0 @@
1
- {
2
- "targets": [
3
- {
4
- "target_name": "decibri",
5
- "sources": [
6
- "src/decibri.cc",
7
-
8
- "deps/portaudio/src/common/pa_allocation.c",
9
- "deps/portaudio/src/common/pa_converters.c",
10
- "deps/portaudio/src/common/pa_cpuload.c",
11
- "deps/portaudio/src/common/pa_dither.c",
12
- "deps/portaudio/src/common/pa_debugprint.c",
13
- "deps/portaudio/src/common/pa_front.c",
14
- "deps/portaudio/src/common/pa_process.c",
15
- "deps/portaudio/src/common/pa_ringbuffer.c",
16
- "deps/portaudio/src/common/pa_stream.c",
17
- "deps/portaudio/src/common/pa_trace.c"
18
- ],
19
-
20
- "include_dirs": [
21
- "<!@(node -p \"require('node-addon-api').include\")",
22
- "deps/portaudio/include",
23
- "deps/portaudio/src/common"
24
- ],
25
-
26
- "defines": [
27
- "NAPI_DISABLE_CPP_EXCEPTIONS",
28
- "NAPI_VERSION=6",
29
- "DECIBRI_VERSION=\"<!@(node -p \"require('./package.json').version\")\""
30
- ],
31
-
32
- "cflags!": ["-fno-exceptions"],
33
- "cflags_cc!": ["-fno-exceptions"],
34
-
35
- "conditions": [
36
-
37
- ["OS=='win'", {
38
- "sources": [
39
- "deps/portaudio/src/os/win/pa_win_util.c",
40
- "deps/portaudio/src/os/win/pa_win_version.c",
41
- "deps/portaudio/src/os/win/pa_win_waveformat.c",
42
- "deps/portaudio/src/os/win/pa_win_hostapis.c",
43
- "deps/portaudio/src/os/win/pa_win_coinitialize.c",
44
- "deps/portaudio/src/hostapi/wasapi/pa_win_wasapi.c"
45
- ],
46
- "include_dirs": [
47
- "deps/portaudio/src/os/win"
48
- ],
49
- "defines": [
50
- "PA_USE_WASAPI=1"
51
- ],
52
- "libraries": [
53
- "-lole32",
54
- "-lwinmm",
55
- "-lksuser",
56
- "-luuid",
57
- "-lavrt"
58
- ],
59
- "msvs_settings": {
60
- "VCCLCompilerTool": {
61
- "ExceptionHandling": 1
62
- }
63
- }
64
- }],
65
-
66
- ["OS=='mac'", {
67
- "sources": [
68
- "deps/portaudio/src/os/unix/pa_unix_util.c",
69
- "deps/portaudio/src/os/unix/pa_unix_hostapis.c",
70
- "deps/portaudio/src/hostapi/coreaudio/pa_mac_core.c",
71
- "deps/portaudio/src/hostapi/coreaudio/pa_mac_core_utilities.c",
72
- "deps/portaudio/src/hostapi/coreaudio/pa_mac_core_blocking.c",
73
- "src/mac_permission.mm"
74
- ],
75
- "include_dirs": [
76
- "deps/portaudio/src/os/unix",
77
- "deps/portaudio/src/hostapi/coreaudio"
78
- ],
79
- "defines": [
80
- "PA_USE_COREAUDIO=1"
81
- ],
82
- "link_settings": {
83
- "libraries": [
84
- "-framework CoreAudio",
85
- "-framework AudioToolbox",
86
- "-framework AudioUnit",
87
- "-framework CoreServices",
88
- "-framework Carbon",
89
- "-framework AVFoundation"
90
- ]
91
- },
92
- "xcode_settings": {
93
- "GCC_ENABLE_CPP_EXCEPTIONS": "YES",
94
- "CLANG_CXX_LIBRARY": "libc++",
95
- "MACOSX_DEPLOYMENT_TARGET": "10.15",
96
- "OTHER_CFLAGS": ["-mmacosx-version-min=10.15"],
97
- "OTHER_CPLUSPLUSFLAGS": ["-mmacosx-version-min=10.15"]
98
- }
99
- }],
100
-
101
- ["OS=='linux'", {
102
- "sources": [
103
- "deps/portaudio/src/os/unix/pa_unix_util.c",
104
- "deps/portaudio/src/os/unix/pa_unix_hostapis.c",
105
- "deps/portaudio/src/hostapi/alsa/pa_linux_alsa.c"
106
- ],
107
- "include_dirs": [
108
- "deps/portaudio/src/os/unix"
109
- ],
110
- "defines": [
111
- "PA_USE_ALSA=1"
112
- ],
113
- "libraries": [
114
- "-lasound",
115
- "-lpthread"
116
- ]
117
- }]
118
-
119
- ]
120
- }
121
- ]
122
- }
@@ -1,48 +0,0 @@
1
- 'use strict';
2
- // Captures audio for DURATION_MS and writes a valid WAV file.
3
- // No external dependencies — uses Node.js built-ins only.
4
- // Usage: node examples/wav-capture.js
5
-
6
- const fs = require('fs');
7
- // In your own project: const Decibri = require('decibri');
8
- const Decibri = require('../index');
9
-
10
- const SAMPLE_RATE = 16000;
11
- const CHANNELS = 1;
12
- const BITS_PER_SAMPLE = 16;
13
- const DURATION_MS = 5000;
14
-
15
- const mic = new Decibri({ sampleRate: SAMPLE_RATE, channels: CHANNELS });
16
- const chunks = [];
17
-
18
- mic.on('data', (chunk) => chunks.push(chunk));
19
- mic.on('error', (err) => { console.error('Mic error:', err.message); process.exit(1); });
20
-
21
- console.log(`Recording for ${DURATION_MS / 1000} seconds...`);
22
-
23
- setTimeout(() => {
24
- mic.stop();
25
-
26
- const pcm = Buffer.concat(chunks);
27
- const header = buildWavHeader(pcm.length, SAMPLE_RATE, CHANNELS, BITS_PER_SAMPLE);
28
- const out = fs.createWriteStream('capture.wav');
29
- out.write(header);
30
- out.end(pcm);
31
- out.on('finish', () =>
32
- console.log(`Wrote capture.wav (${(pcm.length / 1024).toFixed(1)} KB PCM, ${DURATION_MS / 1000}s)`)
33
- );
34
- }, DURATION_MS);
35
-
36
- function buildWavHeader(dataBytes, sampleRate, channels, bitsPerSample) {
37
- const byteRate = sampleRate * channels * bitsPerSample / 8;
38
- const blockAlign = channels * bitsPerSample / 8;
39
- const buf = Buffer.alloc(44);
40
- buf.write('RIFF', 0); buf.writeUInt32LE(36 + dataBytes, 4);
41
- buf.write('WAVE', 8); buf.write('fmt ', 12);
42
- buf.writeUInt32LE(16, 16); buf.writeUInt16LE(1, 20); // PCM
43
- buf.writeUInt16LE(channels, 22); buf.writeUInt32LE(sampleRate, 24);
44
- buf.writeUInt32LE(byteRate, 28); buf.writeUInt16LE(blockAlign, 32);
45
- buf.writeUInt16LE(bitsPerSample,34);
46
- buf.write('data', 36); buf.writeUInt32LE(dataBytes, 40);
47
- return buf;
48
- }
@@ -1,28 +0,0 @@
1
- 'use strict';
2
- // Minimal WebSocket server that receives raw PCM chunks and logs byte counts.
3
- // Use this to test examples/websocket-stream.js.
4
- // Requires: npm install ws
5
- // Usage: node examples/websocket-server.js
6
-
7
- const { WebSocketServer } = require('ws');
8
-
9
- const wss = new WebSocketServer({ port: 8080 });
10
- console.log('Listening on ws://localhost:8080');
11
-
12
- wss.on('connection', (ws) => {
13
- console.log('Client connected');
14
- let total = 0;
15
-
16
- ws.on('message', (data) => {
17
- total += data.length;
18
- process.stdout.write(`\rReceived ${(total / 1024).toFixed(1)} KB`);
19
- });
20
-
21
- ws.on('close', () => {
22
- console.log(`\nClient disconnected. Total received: ${(total / 1024).toFixed(1)} KB`);
23
- });
24
-
25
- ws.on('error', (err) => {
26
- console.error('\nWebSocket error:', err.message);
27
- });
28
- });