recorder-client 1.0.3 → 1.0.5

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
@@ -28,7 +28,7 @@ npm i recorder-client
28
28
  | onpause | () => void | pause event |
29
29
  | onresume | () => void | resume event |
30
30
  | onstart | () => void | start event |
31
- | onstop | (wav: Blob) => void | stop event |
31
+ | onstop | (pcm: Int16Array) => void | stop event |
32
32
  | pause | () => void | audio pause |
33
33
  | resume | () => void | audio resume |
34
34
  | start | () => void | audio start |
@@ -36,12 +36,12 @@ npm i recorder-client
36
36
 
37
37
  ### Helper
38
38
 
39
- | property | type | description |
40
- | :--------: | :----------------------------------------------: | :-----------------------------------: |
41
- | pcmMerge | (pcms: Int16Array[]) => Int16Array<ArrayBuffer> | merge multiple pcm streams |
42
- | pcmToWav | (pcm: Int16Array, sampleRate: number) => Blob | convert PCM to WAV |
43
- | parseWav | (buffer: ArrayBuffer) => object | obtain information about the wav file |
44
- | isSpeaking | (pcm: Int16Array, sampleRate: number) => boolean | check if there is any input of audio |
39
+ | property | type | description |
40
+ | :------: | :----------------------------------------------: | :-----------------------------------: |
41
+ | pcmMerge | (pcms: Int16Array[]) => Int16Array | merge multiple pcm streams |
42
+ | pcmToWav | (pcm: Int16Array, sampleRate: number) => Blob | convert PCM to WAV |
43
+ | parseWav | (buffer: ArrayBuffer) => object | obtain information about the wav file |
44
+ | isSpeak | (pcm: Int16Array, sampleRate: number) => boolean | check if there is any input of audio |
45
45
 
46
46
  ### Example
47
47
 
@@ -58,7 +58,7 @@ const recorder = new Recorder({
58
58
  recorder.onstart = () => {};
59
59
  recorder.onpause = () => {};
60
60
  recorder.onresume = () => {};
61
- recorder.onstop = (blob) => {};
61
+ recorder.onstop = (pcm) => {};
62
62
  recorder.ondataavailable = (pcm) => {};
63
63
 
64
64
  const onClick = () => {
@@ -86,7 +86,7 @@ recorder.ondataavailable = (pcm) => {
86
86
  };
87
87
 
88
88
  const onMerge = () => {
89
- return Recorder.pcmMerge(pcms);
89
+ const data = Recorder.pcmMerge(pcms);
90
90
  };
91
91
  ```
92
92
 
@@ -100,7 +100,7 @@ const recorder = new Recorder({
100
100
  chunkSize: 1900,
101
101
  });
102
102
 
103
- recorder.ondataavailable = (pcm) => {
103
+ recorder.onstop = (pcm) => {
104
104
  const blob = pcmToWav(pcm, 16000);
105
105
  };
106
106
  ```
@@ -124,7 +124,7 @@ const getWav = async (file: File) => {
124
124
  };
125
125
  ```
126
126
 
127
- > isSpeaking
127
+ > isSpeak
128
128
 
129
129
  ```ts
130
130
  import { Recorder } from 'recorder-client';
@@ -135,6 +135,6 @@ const recorder = new Recorder({
135
135
  });
136
136
 
137
137
  recorder.ondataavailable = (pcm) => {
138
- const flag = Recorder.isSpeaking(pcm, 16000);
138
+ const flag = Recorder.isSpeak(pcm, 16000);
139
139
  };
140
140
  ```
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.isSpeaking(data, sampleRate)) {
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.pcmToWav(Recorder.pcmMerge(this._pcmData), this._options.sampleRate));
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 isSpeaking(int16Array, sampleRate) {
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?: (blob: Blob) => void;
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<ArrayBuffer>;
23
+ static pcmMerge(arrays: Int16Array[]): Int16Array;
24
24
  static pcmToWav(data: Int16Array, sampleRate: number): Blob;
25
- static isSpeaking(int16Array: Int16Array, sampleRate: number): boolean;
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.isSpeaking(data, sampleRate)) {
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.pcmToWav(Recorder.pcmMerge(this._pcmData), this._options.sampleRate));
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 isSpeaking(int16Array, sampleRate) {
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",
3
+ "version": "1.0.5",
4
4
  "description": "audio recording client",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",