dspx 1.0.1 → 1.1.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/README.md +56 -16
- package/dist/bindings.d.ts +272 -1
- package/dist/bindings.d.ts.map +1 -1
- package/dist/bindings.js +419 -1
- package/dist/bindings.js.map +1 -1
- package/dist/types.d.ts +235 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -1
- package/prebuilds/darwin-arm64/dspx.node +0 -0
- package/prebuilds/win32-x64/dspx.node +0 -0
- package/scripts/install.js +98 -0
- package/scripts/postinstall-verify.js +32 -0
- package/scripts/test-install.js +82 -0
- package/scripts/test.js +24 -0
- package/src/native/DspPipeline.cc +105 -0
- package/src/native/adapters/MelSpectrogramStage.h +211 -0
- package/src/native/adapters/MfccStage.h +220 -0
- package/src/native/adapters/StftStage.h +466 -0
- package/src/native/core/DctEngine.h +172 -0
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# dspx
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/dspx)
|
|
4
|
-
[](#-quick-start)
|
|
5
5
|
[](https://www.typescriptlang.org/)
|
|
6
6
|
[](./LICENSE)
|
|
7
7
|
|
|
@@ -342,7 +342,7 @@ const output = await pipeline.process(input, {
|
|
|
342
342
|
| Batched callbacks | 3.2M samples/sec | ✅ **Recommended** for production |
|
|
343
343
|
| Individual callbacks | 6.1M samples/sec | ⚠️ Development/debugging only |
|
|
344
344
|
|
|
345
|
-
**SIMD Acceleration:** Batch operations and rectification are 2-8x faster with AVX2/SSE2/NEON on x86_64. See [SIMD_OPTIMIZATIONS.md](https://github.com/A-KGeorge/
|
|
345
|
+
**SIMD Acceleration:** Batch operations and rectification are 2-8x faster with AVX2/SSE2/NEON on x86_64. See [SIMD_OPTIMIZATIONS.md](https://github.com/A-KGeorge/dspx/blob/main/docs/SIMD_OPTIMIZATIONS.md) for details.
|
|
346
346
|
|
|
347
347
|
**Recommendation:** Use batched callbacks in production. Individual callbacks benchmark faster but block the Node.js event loop and can't integrate with real telemetry systems (Kafka, Datadog, Loki).
|
|
348
348
|
|
|
@@ -362,21 +362,61 @@ const output = await pipeline.process(input, {
|
|
|
362
362
|
|
|
363
363
|
**We welcome contributions!** If you have ARM optimization expertise or access to ARM development hardware, please open an issue or PR. Mobile DSP is challenging and community input helps improve real-world performance.
|
|
364
364
|
|
|
365
|
-
📖 **Read more:** [ARM Platform Status & Performance Notes](https://github.com/A-KGeorge/
|
|
365
|
+
📖 **Read more:** [ARM Platform Status & Performance Notes](https://github.com/A-KGeorge/dspx/blob/main/docs/ARM_PLATFORM_STATUS.md)
|
|
366
366
|
|
|
367
367
|
---
|
|
368
368
|
|
|
369
369
|
## 📦 Installation
|
|
370
370
|
|
|
371
371
|
```bash
|
|
372
|
-
npm install dspx
|
|
372
|
+
npm install dspx
|
|
373
373
|
```
|
|
374
374
|
|
|
375
|
-
|
|
375
|
+
### Smart Installation
|
|
376
376
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
-
|
|
377
|
+
dspx uses an intelligent installation strategy for optimal performance and ease of use:
|
|
378
|
+
|
|
379
|
+
- **x64/x86 Architectures** (Intel/AMD): Uses prebuilt binaries
|
|
380
|
+
|
|
381
|
+
- ✅ No C++ compiler needed
|
|
382
|
+
- ⚡ Fast installation (~5 seconds)
|
|
383
|
+
- 🎯 Works out of the box
|
|
384
|
+
|
|
385
|
+
- **ARM Architectures** (Apple Silicon, Raspberry Pi, AWS Graviton): Compiles locally
|
|
386
|
+
- 🔧 Requires C++ build tools (see below)
|
|
387
|
+
- 🚀 Optimized for your specific ARM CPU
|
|
388
|
+
- 💪 Better performance than generic prebuilds
|
|
389
|
+
|
|
390
|
+
### Build Tools (ARM only)
|
|
391
|
+
|
|
392
|
+
If you're on ARM architecture, install build tools first:
|
|
393
|
+
|
|
394
|
+
**macOS (Apple Silicon M1/M2/M3):**
|
|
395
|
+
|
|
396
|
+
```bash
|
|
397
|
+
xcode-select --install
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
**Linux (Raspberry Pi, AWS Graviton):**
|
|
401
|
+
|
|
402
|
+
```bash
|
|
403
|
+
sudo apt-get update
|
|
404
|
+
sudo apt-get install build-essential
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
**Windows (ARM64):**
|
|
408
|
+
|
|
409
|
+
```bash
|
|
410
|
+
npm install --global windows-build-tools
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
### Supported Platforms
|
|
414
|
+
|
|
415
|
+
- ✅ Node.js 18, 20, 22 (LTS versions)
|
|
416
|
+
- ✅ Windows x64, Linux x64, macOS x64
|
|
417
|
+
- ✅ macOS arm64 (Apple Silicon)
|
|
418
|
+
- ✅ Linux arm64 (AWS Graviton, Raspberry Pi 4+)
|
|
419
|
+
- ✅ Linux armv7 (Raspberry Pi 3)
|
|
380
420
|
|
|
381
421
|
---
|
|
382
422
|
|
|
@@ -453,7 +493,7 @@ const smoothed = await pipeline.process(samples, timestamps, { channels: 1 });
|
|
|
453
493
|
console.log(smoothed); // Time-aware smoothing
|
|
454
494
|
```
|
|
455
495
|
|
|
456
|
-
**📚 [Complete Time-Series Guide →](https://github.com/A-KGeorge/
|
|
496
|
+
**📚 [Complete Time-Series Guide →](https://github.com/A-KGeorge/dspx/blob/main/docs/time-series-guide.md)**
|
|
457
497
|
|
|
458
498
|
### Processing Without Modifying Input
|
|
459
499
|
|
|
@@ -538,7 +578,7 @@ const consumer = await createKafkaConsumer({
|
|
|
538
578
|
await consumer.run();
|
|
539
579
|
```
|
|
540
580
|
|
|
541
|
-
**See [Kafka Integration Guide](https://github.com/A-KGeorge/
|
|
581
|
+
**See [Kafka Integration Guide](https://github.com/A-KGeorge/dspx/blob/main/docs/KAFKA_INTEGRATION.md) for real-time streaming examples.**
|
|
542
582
|
|
|
543
583
|
### Multi-Channel Processing
|
|
544
584
|
|
|
@@ -600,7 +640,7 @@ await pipeline.process(samples: Float32Array, options: {
|
|
|
600
640
|
});
|
|
601
641
|
```
|
|
602
642
|
|
|
603
|
-
**See [Time-Series Guide](https://github.com/A-KGeorge/
|
|
643
|
+
**See [Time-Series Guide](https://github.com/A-KGeorge/dspx/blob/main/docs/time-series-guide.md) for detailed examples.**
|
|
604
644
|
|
|
605
645
|
### Available Filters
|
|
606
646
|
|
|
@@ -1568,7 +1608,7 @@ const activityLevel = await activityPipeline.process(multiChannelData, {
|
|
|
1568
1608
|
- **Transform Domain**: STFT, Hilbert transform, wavelet transforms
|
|
1569
1609
|
- **Feature Extraction**: Zero-crossing rate, peak detection, autocorrelation
|
|
1570
1610
|
|
|
1571
|
-
See the [project roadmap](https://github.com/A-KGeorge/
|
|
1611
|
+
See the [project roadmap](https://github.com/A-KGeorge/dspx/blob/main/ROADMAP.md) for more details.
|
|
1572
1612
|
|
|
1573
1613
|
---
|
|
1574
1614
|
|
|
@@ -1602,7 +1642,7 @@ const pipeline = createDspPipeline()
|
|
|
1602
1642
|
.Rms({ windowSize: 5 });
|
|
1603
1643
|
```
|
|
1604
1644
|
|
|
1605
|
-
**📚 [Full Advanced Features Documentation](https://github.com/A-KGeorge/
|
|
1645
|
+
**📚 [Full Advanced Features Documentation](https://github.com/A-KGeorge/dspx/blob/main/docs/advanced.md)**
|
|
1606
1646
|
|
|
1607
1647
|
Key highlights:
|
|
1608
1648
|
|
|
@@ -1756,7 +1796,7 @@ const smoothed = await pipeline.process(samples, timestamps, { channels: 1 });
|
|
|
1756
1796
|
// Properly handles irregular sampling intervals!
|
|
1757
1797
|
```
|
|
1758
1798
|
|
|
1759
|
-
**📚 [More Time-Series Examples →](https://github.com/A-KGeorge/
|
|
1799
|
+
**📚 [More Time-Series Examples →](https://github.com/A-KGeorge/dspx/blob/main/docs/time-series-guide.md#real-world-examples)**
|
|
1760
1800
|
|
|
1761
1801
|
### Streaming Data with Crash Recovery
|
|
1762
1802
|
|
|
@@ -1888,7 +1928,7 @@ await worker2.process(chunk2, { sampleRate: 2000, channels: 1 });
|
|
|
1888
1928
|
### Building from Source
|
|
1889
1929
|
|
|
1890
1930
|
```bash
|
|
1891
|
-
git clone https://github.com/A-KGeorge/
|
|
1931
|
+
git clone https://github.com/A-KGeorge/dspx.git
|
|
1892
1932
|
cd dspx
|
|
1893
1933
|
npm install
|
|
1894
1934
|
npm run build # Compile C++ bindings with cmake-js
|
|
@@ -2258,7 +2298,7 @@ Contributions are welcome! This project is in active development.
|
|
|
2258
2298
|
### Development Workflow
|
|
2259
2299
|
|
|
2260
2300
|
```bash
|
|
2261
|
-
git clone https://github.com/A-KGeorge/
|
|
2301
|
+
git clone https://github.com/A-KGeorge/dspx.git
|
|
2262
2302
|
cd dspx
|
|
2263
2303
|
npm install
|
|
2264
2304
|
npm run build # Compile C++ with cmake-js
|
package/dist/bindings.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ProcessOptions, RedisConfig, MovingAverageParams, RmsParams, RectifyParams, VarianceParams, ZScoreNormalizeParams, MeanAbsoluteValueParams, WaveformLengthParams, SlopeSignChangeParams, WillisonAmplitudeParams, LinearRegressionParams, LmsFilterParams, InterpolateParams, DecimateParams, ResampleParams, ConvolutionParams, WaveletTransformParams, HilbertEnvelopeParams, PipelineCallbacks, RlsFilterParams, TapCallback, PipelineStateSummary, BeamformerWeightsResult, CspResult, GscPreprocessorParams, ChannelSelectorParams, ChannelSelectParams, ChannelMergeParams, ClipDetectionParams, PeakDetectionParams, CspTransformParams } from "./types.js";
|
|
1
|
+
import type { ProcessOptions, RedisConfig, MovingAverageParams, RmsParams, RectifyParams, VarianceParams, ZScoreNormalizeParams, MeanAbsoluteValueParams, WaveformLengthParams, SlopeSignChangeParams, WillisonAmplitudeParams, LinearRegressionParams, LmsFilterParams, InterpolateParams, DecimateParams, ResampleParams, ConvolutionParams, WaveletTransformParams, HilbertEnvelopeParams, PipelineCallbacks, RlsFilterParams, TapCallback, PipelineStateSummary, BeamformerWeightsResult, CspResult, GscPreprocessorParams, ChannelSelectorParams, ChannelSelectParams, ChannelMergeParams, ClipDetectionParams, PeakDetectionParams, CspTransformParams, fftParams, stftParams, MelSpectrogramParams, MfccParams } from "./types.js";
|
|
2
2
|
import { type FilterOptions } from "./filters.js";
|
|
3
3
|
/**
|
|
4
4
|
* DSP Processor class that wraps the native C++ DspPipeline
|
|
@@ -1032,6 +1032,277 @@ declare class DspProcessor {
|
|
|
1032
1032
|
* .MovingAverage({ mode: "moving", windowSize: 10 });
|
|
1033
1033
|
*/
|
|
1034
1034
|
HilbertEnvelope(params: HilbertEnvelopeParams): this;
|
|
1035
|
+
/**
|
|
1036
|
+
* Add FFT (Fast Fourier Transform) stage to the pipeline
|
|
1037
|
+
*
|
|
1038
|
+
* Transforms time-domain signal to frequency domain or vice versa.
|
|
1039
|
+
* Supports both fast (radix-2) and direct (any size) transforms.
|
|
1040
|
+
*
|
|
1041
|
+
* **Transform Types:**
|
|
1042
|
+
* - `fft`: Complex FFT (O(N log N), requires power-of-2 size)
|
|
1043
|
+
* - `dft`: Complex DFT (O(N²), works with any size)
|
|
1044
|
+
* - `rfft`: Real FFT for real signals (O(N log N), outputs N/2+1 bins)
|
|
1045
|
+
* - `rdft`: Real DFT for real signals (O(N²), outputs N/2+1 bins)
|
|
1046
|
+
*
|
|
1047
|
+
* **Output Formats:**
|
|
1048
|
+
* - `complex`: Returns interleaved [real0, imag0, real1, imag1, ...]
|
|
1049
|
+
* - `magnitude`: Returns |X[k]| = sqrt(real² + imag²)
|
|
1050
|
+
* - `power`: Returns |X[k]|² = real² + imag²
|
|
1051
|
+
* - `phase`: Returns ∠X[k] = atan2(imag, real)
|
|
1052
|
+
*
|
|
1053
|
+
* @param params - FFT configuration
|
|
1054
|
+
* @param params.size - FFT size (power of 2 for FFT/RFFT, any size for DFT/RDFT)
|
|
1055
|
+
* @param params.type - Transform type (default: 'rfft' for real signals)
|
|
1056
|
+
* @param params.forward - Forward (time→freq) or inverse (freq→time) (default: true)
|
|
1057
|
+
* @param params.output - Output format (default: 'magnitude')
|
|
1058
|
+
* @returns this instance for method chaining
|
|
1059
|
+
*
|
|
1060
|
+
* @example
|
|
1061
|
+
* // Spectral analysis with magnitude output
|
|
1062
|
+
* pipeline.fft({
|
|
1063
|
+
* size: 1024,
|
|
1064
|
+
* type: 'rfft',
|
|
1065
|
+
* output: 'magnitude'
|
|
1066
|
+
* });
|
|
1067
|
+
*
|
|
1068
|
+
* @example
|
|
1069
|
+
* // Power spectrum for energy analysis
|
|
1070
|
+
* pipeline.fft({
|
|
1071
|
+
* size: 2048,
|
|
1072
|
+
* output: 'power'
|
|
1073
|
+
* });
|
|
1074
|
+
*
|
|
1075
|
+
* @example
|
|
1076
|
+
* // Complex FFT for phase information
|
|
1077
|
+
* pipeline.fft({
|
|
1078
|
+
* size: 512,
|
|
1079
|
+
* type: 'fft',
|
|
1080
|
+
* output: 'complex'
|
|
1081
|
+
* });
|
|
1082
|
+
*
|
|
1083
|
+
* @example
|
|
1084
|
+
* // DFT for non-power-of-2 sizes
|
|
1085
|
+
* pipeline.fft({
|
|
1086
|
+
* size: 1000, // Not a power of 2
|
|
1087
|
+
* type: 'rdft',
|
|
1088
|
+
* output: 'magnitude'
|
|
1089
|
+
* });
|
|
1090
|
+
*/
|
|
1091
|
+
fft(params: fftParams): this;
|
|
1092
|
+
/**
|
|
1093
|
+
* Helper to check if a number is a power of 2
|
|
1094
|
+
*/
|
|
1095
|
+
private isPowerOfTwo;
|
|
1096
|
+
/**
|
|
1097
|
+
* Add STFT (Short-Time Fourier Transform) stage to the pipeline
|
|
1098
|
+
*
|
|
1099
|
+
* Computes time-frequency representation by applying FFT/DFT to overlapping windows.
|
|
1100
|
+
* Produces a spectrogram showing how frequency content evolves over time.
|
|
1101
|
+
*
|
|
1102
|
+
* **Use Cases:**
|
|
1103
|
+
* - Audio spectrograms for music/speech analysis
|
|
1104
|
+
* - Non-stationary signal analysis (EEG, vibration)
|
|
1105
|
+
* - Feature extraction for machine learning
|
|
1106
|
+
* - Time-varying frequency detection
|
|
1107
|
+
*
|
|
1108
|
+
* **Time-Frequency Resolution Trade-off:**
|
|
1109
|
+
* - Larger window → Better frequency resolution, worse time resolution
|
|
1110
|
+
* - Smaller window → Better time resolution, worse frequency resolution
|
|
1111
|
+
*
|
|
1112
|
+
* **Output Format:**
|
|
1113
|
+
* The output is a flattened 2D array: [window0_bin0, window0_bin1, ..., window1_bin0, ...]
|
|
1114
|
+
* - Rows: Time windows (numWindows)
|
|
1115
|
+
* - Cols: Frequency bins (windowSize/2+1 for real, windowSize for complex)
|
|
1116
|
+
*
|
|
1117
|
+
* @param params - STFT configuration
|
|
1118
|
+
* @param params.windowSize - FFT window size (power of 2 for FFT, any size for DFT)
|
|
1119
|
+
* @param params.hopSize - Stride between windows (default: windowSize/2, i.e., 50% overlap)
|
|
1120
|
+
* @param params.method - 'fft' or 'dft' (default: auto-detect based on windowSize)
|
|
1121
|
+
* @param params.type - 'real' or 'complex' input (default: 'real')
|
|
1122
|
+
* @param params.forward - true for forward STFT, false for inverse (default: true)
|
|
1123
|
+
* @param params.output - 'complex', 'magnitude', 'power', or 'phase' (default: 'magnitude')
|
|
1124
|
+
* @param params.window - Window function: 'none', 'hann', 'hamming', 'blackman', 'bartlett' (default: 'hann')
|
|
1125
|
+
* @returns this instance for method chaining
|
|
1126
|
+
*
|
|
1127
|
+
* @example
|
|
1128
|
+
* // Audio spectrogram with default settings
|
|
1129
|
+
* pipeline.stft({
|
|
1130
|
+
* windowSize: 1024,
|
|
1131
|
+
* hopSize: 512, // 50% overlap
|
|
1132
|
+
* output: 'magnitude'
|
|
1133
|
+
* });
|
|
1134
|
+
*
|
|
1135
|
+
* @example
|
|
1136
|
+
* // High time resolution for transient detection
|
|
1137
|
+
* pipeline.stft({
|
|
1138
|
+
* windowSize: 256, // Small window
|
|
1139
|
+
* hopSize: 64, // 75% overlap
|
|
1140
|
+
* window: 'hann'
|
|
1141
|
+
* });
|
|
1142
|
+
*
|
|
1143
|
+
* @example
|
|
1144
|
+
* // High frequency resolution for harmonic analysis
|
|
1145
|
+
* pipeline.stft({
|
|
1146
|
+
* windowSize: 4096, // Large window
|
|
1147
|
+
* hopSize: 2048,
|
|
1148
|
+
* output: 'power',
|
|
1149
|
+
* window: 'blackman'
|
|
1150
|
+
* });
|
|
1151
|
+
*
|
|
1152
|
+
* @example
|
|
1153
|
+
* // Complex output for phase vocoding
|
|
1154
|
+
* pipeline.stft({
|
|
1155
|
+
* windowSize: 2048,
|
|
1156
|
+
* hopSize: 512,
|
|
1157
|
+
* output: 'complex'
|
|
1158
|
+
* });
|
|
1159
|
+
*
|
|
1160
|
+
* @example
|
|
1161
|
+
* // Non-power-of-2 with DFT
|
|
1162
|
+
* pipeline.stft({
|
|
1163
|
+
* windowSize: 1000,
|
|
1164
|
+
* method: 'dft',
|
|
1165
|
+
* output: 'magnitude'
|
|
1166
|
+
* });
|
|
1167
|
+
*/
|
|
1168
|
+
stft(params: stftParams): this;
|
|
1169
|
+
/**
|
|
1170
|
+
* Apply Mel Spectrogram conversion to power spectrum
|
|
1171
|
+
*
|
|
1172
|
+
* Converts linear frequency spectrum to Mel-scale representation using a pre-computed
|
|
1173
|
+
* filterbank matrix. The Mel scale is perceptually motivated and better matches human
|
|
1174
|
+
* hearing's frequency resolution.
|
|
1175
|
+
*
|
|
1176
|
+
* **Typical Pipeline:**
|
|
1177
|
+
* ```
|
|
1178
|
+
* STFT → Power → MelSpectrogram → Log → MFCC
|
|
1179
|
+
* ```
|
|
1180
|
+
*
|
|
1181
|
+
* **What it does:**
|
|
1182
|
+
* - Matrix multiplication: mel_energies = filterbank × power_spectrum
|
|
1183
|
+
* - Groups frequency bins into perceptually-meaningful Mel bands
|
|
1184
|
+
* - High-performance C++ implementation using Eigen
|
|
1185
|
+
*
|
|
1186
|
+
* @param params - Mel spectrogram configuration (filterbank, numBins, numMelBands)
|
|
1187
|
+
* @returns this instance for method chaining
|
|
1188
|
+
*
|
|
1189
|
+
* @example
|
|
1190
|
+
* // Create Mel filterbank (helper function needed)
|
|
1191
|
+
* const filterbank = createMelFilterbank({
|
|
1192
|
+
* sampleRate: 16000,
|
|
1193
|
+
* numBins: 257, // from FFT size 512
|
|
1194
|
+
* numMelBands: 40,
|
|
1195
|
+
* fMin: 0,
|
|
1196
|
+
* fMax: 8000
|
|
1197
|
+
* });
|
|
1198
|
+
*
|
|
1199
|
+
* pipeline
|
|
1200
|
+
* .stft({ windowSize: 512, output: 'power' })
|
|
1201
|
+
* .melSpectrogram({
|
|
1202
|
+
* filterbankMatrix: filterbank,
|
|
1203
|
+
* numBins: 257,
|
|
1204
|
+
* numMelBands: 40
|
|
1205
|
+
* });
|
|
1206
|
+
*
|
|
1207
|
+
* @example
|
|
1208
|
+
* // Speech recognition pipeline
|
|
1209
|
+
* const filterbank = createMelFilterbank({
|
|
1210
|
+
* sampleRate: 16000,
|
|
1211
|
+
* numBins: 513,
|
|
1212
|
+
* numMelBands: 26,
|
|
1213
|
+
* fMin: 20,
|
|
1214
|
+
* fMax: 8000
|
|
1215
|
+
* });
|
|
1216
|
+
*
|
|
1217
|
+
* pipeline
|
|
1218
|
+
* .stft({ windowSize: 1024, output: 'power' })
|
|
1219
|
+
* .melSpectrogram({
|
|
1220
|
+
* filterbankMatrix: filterbank,
|
|
1221
|
+
* numBins: 513,
|
|
1222
|
+
* numMelBands: 26
|
|
1223
|
+
* })
|
|
1224
|
+
* .mfcc({ numMelBands: 26, numCoefficients: 13 });
|
|
1225
|
+
*/
|
|
1226
|
+
melSpectrogram(params: MelSpectrogramParams): this;
|
|
1227
|
+
/**
|
|
1228
|
+
* Extract MFCC (Mel-Frequency Cepstral Coefficients) features
|
|
1229
|
+
*
|
|
1230
|
+
* Applies Discrete Cosine Transform (DCT) to log Mel energies to produce MFCCs.
|
|
1231
|
+
* MFCCs are the standard features for speech recognition, speaker identification,
|
|
1232
|
+
* and audio classification because they:
|
|
1233
|
+
* - Decorrelate Mel energies
|
|
1234
|
+
* - Compress information into lower-order coefficients
|
|
1235
|
+
* - Mimic human auditory perception
|
|
1236
|
+
* - Provide compact representation for ML models
|
|
1237
|
+
*
|
|
1238
|
+
* **Typical Pipeline:**
|
|
1239
|
+
* ```
|
|
1240
|
+
* STFT → Power → MelSpectrogram → Log → MFCC
|
|
1241
|
+
* ```
|
|
1242
|
+
*
|
|
1243
|
+
* **What it does:**
|
|
1244
|
+
* - Applies DCT-II to (log) Mel energies
|
|
1245
|
+
* - Keeps first N coefficients (typically 13-20)
|
|
1246
|
+
* - Optional cepstral liftering for improved recognition
|
|
1247
|
+
* - High-performance C++ implementation with pre-computed cosine tables
|
|
1248
|
+
*
|
|
1249
|
+
* @param params - MFCC configuration (numMelBands, numCoefficients, options)
|
|
1250
|
+
* @returns this instance for method chaining
|
|
1251
|
+
*
|
|
1252
|
+
* @example
|
|
1253
|
+
* // Standard speech recognition pipeline
|
|
1254
|
+
* const filterbank = createMelFilterbank({
|
|
1255
|
+
* sampleRate: 16000,
|
|
1256
|
+
* numBins: 257,
|
|
1257
|
+
* numMelBands: 26
|
|
1258
|
+
* });
|
|
1259
|
+
*
|
|
1260
|
+
* pipeline
|
|
1261
|
+
* .stft({ windowSize: 512, output: 'power' })
|
|
1262
|
+
* .melSpectrogram({
|
|
1263
|
+
* filterbankMatrix: filterbank,
|
|
1264
|
+
* numBins: 257,
|
|
1265
|
+
* numMelBands: 26
|
|
1266
|
+
* })
|
|
1267
|
+
* .mfcc({
|
|
1268
|
+
* numMelBands: 26,
|
|
1269
|
+
* numCoefficients: 13,
|
|
1270
|
+
* useLogEnergy: true,
|
|
1271
|
+
* lifterCoefficient: 22
|
|
1272
|
+
* });
|
|
1273
|
+
*
|
|
1274
|
+
* @example
|
|
1275
|
+
* // Music classification with more coefficients
|
|
1276
|
+
* pipeline
|
|
1277
|
+
* .stft({ windowSize: 2048, output: 'power' })
|
|
1278
|
+
* .melSpectrogram({
|
|
1279
|
+
* filterbankMatrix: musicFilterbank,
|
|
1280
|
+
* numBins: 1025,
|
|
1281
|
+
* numMelBands: 40
|
|
1282
|
+
* })
|
|
1283
|
+
* .mfcc({
|
|
1284
|
+
* numMelBands: 40,
|
|
1285
|
+
* numCoefficients: 20
|
|
1286
|
+
* });
|
|
1287
|
+
*
|
|
1288
|
+
* @example
|
|
1289
|
+
* // Skip log if input is already in log domain
|
|
1290
|
+
* pipeline
|
|
1291
|
+
* .stft({ windowSize: 512, output: 'power' })
|
|
1292
|
+
* .melSpectrogram({ filterbankMatrix, numBins: 257, numMelBands: 26 })
|
|
1293
|
+
* .tap((samples) => {
|
|
1294
|
+
* // Apply log manually
|
|
1295
|
+
* for (let i = 0; i < samples.length; i++) {
|
|
1296
|
+
* samples[i] = Math.log(samples[i] + 1e-10);
|
|
1297
|
+
* }
|
|
1298
|
+
* })
|
|
1299
|
+
* .mfcc({
|
|
1300
|
+
* numMelBands: 26,
|
|
1301
|
+
* numCoefficients: 13,
|
|
1302
|
+
* useLogEnergy: false // Skip log since we already applied it
|
|
1303
|
+
* });
|
|
1304
|
+
*/
|
|
1305
|
+
mfcc(params: MfccParams): this;
|
|
1035
1306
|
/**
|
|
1036
1307
|
* Tap into the pipeline for debugging and inspection
|
|
1037
1308
|
* The callback is executed synchronously after processing, allowing you to inspect
|
package/dist/bindings.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bindings.d.ts","sourceRoot":"","sources":["../src/ts/bindings.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,SAAS,EACT,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EAGf,WAAW,EACX,oBAAoB,EACpB,uBAAuB,EACvB,SAAS,EACT,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"bindings.d.ts","sourceRoot":"","sources":["../src/ts/bindings.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,SAAS,EACT,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EAGf,WAAW,EACX,oBAAoB,EACpB,uBAAuB,EACvB,SAAS,EACT,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,SAAS,EACT,UAAU,EACV,oBAAoB,EACpB,UAAU,EACX,MAAM,YAAY,CAAC;AAGpB,OAAO,EAGL,KAAK,aAAa,EAGnB,MAAM,cAAc,CAAC;AAiCtB;;;GAGG;AACH,cAAM,YAAY;IAQJ,OAAO,CAAC,cAAc;IAPlC,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,SAAS,CAAC,CAAoB;IACtC,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,YAAY,CACf;IACL,OAAO,CAAC,aAAa,CAA8B;gBAE/B,cAAc,EAAE,GAAG;IAMvC;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAgBxB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAyB1B;;OAEG;IACH;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAe1B;;OAEG;IACH,OAAO,CAAC,OAAO;IAyBf;;OAEG;IACH,OAAO,CAAC,SAAS;IAOjB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,aAAa,CAAC,MAAM,EAAE,mBAA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