recorder-client 1.0.4 → 1.0.6
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 +2 -2
- package/dist/index.cjs.js +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.esm.js +3 -3
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -58,7 +58,7 @@ const recorder = new Recorder({
|
|
|
58
58
|
recorder.onstart = () => {};
|
|
59
59
|
recorder.onpause = () => {};
|
|
60
60
|
recorder.onresume = () => {};
|
|
61
|
-
recorder.onstop = (
|
|
61
|
+
recorder.onstop = (pcm) => {};
|
|
62
62
|
recorder.ondataavailable = (pcm) => {};
|
|
63
63
|
|
|
64
64
|
const onClick = () => {
|
|
@@ -100,7 +100,7 @@ const recorder = new Recorder({
|
|
|
100
100
|
chunkSize: 1900,
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
-
recorder.
|
|
103
|
+
recorder.onstop = (pcm) => {
|
|
104
104
|
const blob = pcmToWav(pcm, 16000);
|
|
105
105
|
};
|
|
106
106
|
```
|
package/dist/index.cjs.js
CHANGED
|
@@ -150,7 +150,7 @@ class Recorder {
|
|
|
150
150
|
const { e, data } = event.data;
|
|
151
151
|
if (e === 'data') {
|
|
152
152
|
if (ignoreMute) {
|
|
153
|
-
if (Recorder.
|
|
153
|
+
if (Recorder.isSpeak(data, sampleRate)) {
|
|
154
154
|
this._pcmData.push(data);
|
|
155
155
|
this.ondataavailable?.(data);
|
|
156
156
|
}
|
|
@@ -181,7 +181,7 @@ class Recorder {
|
|
|
181
181
|
this._source = undefined;
|
|
182
182
|
this._workletNode = undefined;
|
|
183
183
|
this._audioContext = undefined;
|
|
184
|
-
this.onstop?.(Recorder.
|
|
184
|
+
this.onstop?.(Recorder.pcmMerge(this._pcmData));
|
|
185
185
|
this._pcmData = [];
|
|
186
186
|
}
|
|
187
187
|
static pcmMerge(arrays) {
|
|
@@ -234,7 +234,7 @@ class Recorder {
|
|
|
234
234
|
const wavBlob = new Blob([buffer], { type: 'audio/wav' });
|
|
235
235
|
return wavBlob;
|
|
236
236
|
}
|
|
237
|
-
static
|
|
237
|
+
static isSpeak(int16Array, sampleRate) {
|
|
238
238
|
const frameSize = Math.floor(0.02 * sampleRate); // 20ms 帧长度
|
|
239
239
|
const threshold = 0.01; // 能量阈值(需根据实际调整)
|
|
240
240
|
let speakingFrames = 0;
|
package/dist/index.d.ts
CHANGED
|
@@ -14,15 +14,15 @@ declare class Recorder {
|
|
|
14
14
|
onpause?: () => void;
|
|
15
15
|
onresume?: () => void;
|
|
16
16
|
onstart?: () => void;
|
|
17
|
-
onstop?: (
|
|
17
|
+
onstop?: (data: Int16Array) => void;
|
|
18
18
|
constructor(options: RecorderConstructor);
|
|
19
19
|
start(): Promise<void>;
|
|
20
20
|
pause(): void;
|
|
21
21
|
resume(): void;
|
|
22
22
|
stop(): void;
|
|
23
|
-
static pcmMerge(arrays: Int16Array[]): Int16Array
|
|
23
|
+
static pcmMerge(arrays: Int16Array[]): Int16Array;
|
|
24
24
|
static pcmToWav(data: Int16Array, sampleRate: number): Blob;
|
|
25
|
-
static
|
|
25
|
+
static isSpeak(int16Array: Int16Array, sampleRate: number): boolean;
|
|
26
26
|
static parseWav(buffer: ArrayBuffer): {
|
|
27
27
|
numChannels: number;
|
|
28
28
|
sampleRate: number;
|
package/dist/index.esm.js
CHANGED
|
@@ -148,7 +148,7 @@ class Recorder {
|
|
|
148
148
|
const { e, data } = event.data;
|
|
149
149
|
if (e === 'data') {
|
|
150
150
|
if (ignoreMute) {
|
|
151
|
-
if (Recorder.
|
|
151
|
+
if (Recorder.isSpeak(data, sampleRate)) {
|
|
152
152
|
this._pcmData.push(data);
|
|
153
153
|
this.ondataavailable?.(data);
|
|
154
154
|
}
|
|
@@ -179,7 +179,7 @@ class Recorder {
|
|
|
179
179
|
this._source = undefined;
|
|
180
180
|
this._workletNode = undefined;
|
|
181
181
|
this._audioContext = undefined;
|
|
182
|
-
this.onstop?.(Recorder.
|
|
182
|
+
this.onstop?.(Recorder.pcmMerge(this._pcmData));
|
|
183
183
|
this._pcmData = [];
|
|
184
184
|
}
|
|
185
185
|
static pcmMerge(arrays) {
|
|
@@ -232,7 +232,7 @@ class Recorder {
|
|
|
232
232
|
const wavBlob = new Blob([buffer], { type: 'audio/wav' });
|
|
233
233
|
return wavBlob;
|
|
234
234
|
}
|
|
235
|
-
static
|
|
235
|
+
static isSpeak(int16Array, sampleRate) {
|
|
236
236
|
const frameSize = Math.floor(0.02 * sampleRate); // 20ms 帧长度
|
|
237
237
|
const threshold = 0.01; // 能量阈值(需根据实际调整)
|
|
238
238
|
let speakingFrames = 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "recorder-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "audio recording client",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
@@ -23,20 +23,20 @@
|
|
|
23
23
|
"build": "rollup -c rollup.config.js"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@rollup/plugin-commonjs": "^
|
|
26
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
27
27
|
"@rollup/plugin-json": "^6.1.0",
|
|
28
|
-
"@rollup/plugin-node-resolve": "^16.0.
|
|
29
|
-
"@rollup/plugin-replace": "^6.0.
|
|
28
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
29
|
+
"@rollup/plugin-replace": "^6.0.3",
|
|
30
30
|
"@rollup/plugin-terser": "^0.4.4",
|
|
31
|
-
"@rollup/plugin-typescript": "^12.
|
|
32
|
-
"@types/node": "^24.
|
|
33
|
-
"happy-dom": "^
|
|
34
|
-
"rollup": "^4.
|
|
31
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
32
|
+
"@types/node": "^24.9.2",
|
|
33
|
+
"happy-dom": "^20.0.10",
|
|
34
|
+
"rollup": "^4.52.5",
|
|
35
35
|
"rollup-plugin-dts": "^6.2.3",
|
|
36
36
|
"tslib": "^2.8.1",
|
|
37
|
-
"typescript": "^5.9.
|
|
38
|
-
"typescript-eslint-standard": "^9.
|
|
39
|
-
"vitest": "^
|
|
37
|
+
"typescript": "^5.9.3",
|
|
38
|
+
"typescript-eslint-standard": "^9.66.0",
|
|
39
|
+
"vitest": "^4.0.6"
|
|
40
40
|
},
|
|
41
41
|
"author": "mivui",
|
|
42
42
|
"license": "MIT",
|