web-audio-recorder-ts 1.0.0

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.
Files changed (40) hide show
  1. package/LICENSE +62 -0
  2. package/README.md +261 -0
  3. package/dist/core/WebAudioRecorder.d.ts +85 -0
  4. package/dist/core/WebAudioRecorder.d.ts.map +1 -0
  5. package/dist/core/types.d.ts +109 -0
  6. package/dist/core/types.d.ts.map +1 -0
  7. package/dist/encoders/Mp3LameEncoder.d.ts +48 -0
  8. package/dist/encoders/Mp3LameEncoder.d.ts.map +1 -0
  9. package/dist/encoders/OggVorbisEncoder.d.ts +48 -0
  10. package/dist/encoders/OggVorbisEncoder.d.ts.map +1 -0
  11. package/dist/encoders/WavAudioEncoder.d.ts +47 -0
  12. package/dist/encoders/WavAudioEncoder.d.ts.map +1 -0
  13. package/dist/index.cjs.js +770 -0
  14. package/dist/index.cjs.js.map +1 -0
  15. package/dist/index.d.ts +17 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.esm.js +760 -0
  18. package/dist/index.esm.js.map +1 -0
  19. package/dist/index.umd.js +776 -0
  20. package/dist/index.umd.js.map +1 -0
  21. package/dist/lib/Mp3LameEncoder.min.js +18 -0
  22. package/dist/lib/Mp3LameEncoder.min.js.mem +0 -0
  23. package/dist/lib/OggVorbisEncoder.min.js +17 -0
  24. package/dist/lib/OggVorbisEncoder.min.js.mem +0 -0
  25. package/dist/lib/WavAudioEncoder.min.js +1 -0
  26. package/dist/recorders/WebAudioRecorderMp3.d.ts +29 -0
  27. package/dist/recorders/WebAudioRecorderMp3.d.ts.map +1 -0
  28. package/dist/recorders/WebAudioRecorderOgg.d.ts +29 -0
  29. package/dist/recorders/WebAudioRecorderOgg.d.ts.map +1 -0
  30. package/dist/recorders/WebAudioRecorderWav.d.ts +20 -0
  31. package/dist/recorders/WebAudioRecorderWav.d.ts.map +1 -0
  32. package/lib/Mp3LameEncoder.min.js +18 -0
  33. package/lib/Mp3LameEncoder.min.js.mem +0 -0
  34. package/lib/OggVorbisEncoder.min.js +17 -0
  35. package/lib/OggVorbisEncoder.min.js.mem +0 -0
  36. package/lib/WavAudioEncoder.min.js +1 -0
  37. package/package.json +62 -0
  38. package/types/mp3-lame-encoder.d.ts +28 -0
  39. package/types/ogg-vorbis-encoder.d.ts +28 -0
  40. package/types/wav-audio-encoder.d.ts +17 -0
package/LICENSE ADDED
@@ -0,0 +1,62 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 web-audio-recorder-ts contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ OGG Vorbis Encoder License (Xiph BSD License)
26
+
27
+ Copyright (c) 2002-2020, Xiph.org Foundation
28
+
29
+ Redistribution and use in source and binary forms, with or without
30
+ modification, are permitted provided that the following conditions
31
+ are met:
32
+
33
+ - Redistributions of source code must retain the above copyright
34
+ notice, this list of conditions and the following disclaimer.
35
+
36
+ - Redistributions in binary form must reproduce the above copyright
37
+ notice, this list of conditions and the following disclaimer in the
38
+ documentation and/or other materials provided with the distribution.
39
+
40
+ - Neither the name of the Xiph.org Foundation nor the names of its
41
+ contributors may be used to endorse or promote products derived from
42
+ this software without specific prior written permission.
43
+
44
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
45
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
46
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
47
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION
48
+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
49
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
50
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
51
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
52
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
53
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
54
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55
+
56
+ ---
57
+
58
+ MP3 LAME Encoder License (LGPL)
59
+
60
+ The LAME encoder library is licensed under the LGPL (Lesser General Public License).
61
+ Please refer to the LAME project for full license details:
62
+ <http://lame.sourceforge.net/>
package/README.md ADDED
@@ -0,0 +1,261 @@
1
+ # web-audio-recorder-ts
2
+
3
+ TypeScript port of [web-audio-recorder-js](https://github.com/higuma/web-audio-recorder-js) with full type support for WAV, OGG Vorbis, and MP3 audio recording in browsers.
4
+
5
+ ## Features
6
+
7
+ - ✅ Full TypeScript support with type definitions
8
+ - ✅ Record audio in WAV, OGG Vorbis, and MP3 formats
9
+ - ✅ Modern ES modules, CommonJS, and UMD builds
10
+ - ✅ Zero runtime dependencies
11
+ - ✅ Works in browsers and Web Workers
12
+ - ✅ Type-safe API with IntelliSense support
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install web-audio-recorder-ts
18
+ # or
19
+ pnpm add web-audio-recorder-ts
20
+ # or
21
+ yarn add web-audio-recorder-ts
22
+ ```
23
+
24
+ ## Quick Start
25
+
26
+ ### WAV Recording
27
+
28
+ ```typescript
29
+ import { WebAudioRecorderWav } from 'web-audio-recorder-ts';
30
+
31
+ // Create audio context
32
+ const audioContext = new AudioContext();
33
+
34
+ // Get user media
35
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
36
+
37
+ // Create recorder
38
+ const recorder = new WebAudioRecorderWav(audioContext);
39
+
40
+ // Set up callbacks
41
+ recorder.setOnComplete((event) => {
42
+ console.log('Recording complete!', event.url);
43
+ // event.blob contains the WAV file
44
+ // event.url is a blob URL for playback
45
+ });
46
+
47
+ recorder.setOnError((event) => {
48
+ console.error('Error:', event.message);
49
+ });
50
+
51
+ // Start recording
52
+ await recorder.start(stream);
53
+
54
+ // Stop recording (after some time)
55
+ const blob = await recorder.stop();
56
+ ```
57
+
58
+ ### OGG Vorbis Recording
59
+
60
+ ```typescript
61
+ import { WebAudioRecorderOgg, loadOggVorbisEncoder } from 'web-audio-recorder-ts';
62
+
63
+ // Load encoder script first
64
+ await loadOggVorbisEncoder('/path/to/OggVorbisEncoder.min.js');
65
+
66
+ // Configure memory initializer path (if needed)
67
+ if (typeof window !== 'undefined') {
68
+ (window as any).OggVorbisEncoderConfig = {
69
+ memoryInitializerPrefixURL: '/path/to/'
70
+ };
71
+ }
72
+
73
+ const audioContext = new AudioContext();
74
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
75
+
76
+ const recorder = new WebAudioRecorderOgg(
77
+ audioContext,
78
+ {},
79
+ { quality: 0.7 } // OGG quality: -0.1 to 1.0
80
+ );
81
+
82
+ await recorder.start(stream);
83
+ const blob = await recorder.stop();
84
+ ```
85
+
86
+ ### MP3 Recording
87
+
88
+ ```typescript
89
+ import { WebAudioRecorderMp3, loadMp3LameEncoder } from 'web-audio-recorder-ts';
90
+
91
+ // Load encoder script first
92
+ await loadMp3LameEncoder('/path/to/Mp3LameEncoder.min.js');
93
+
94
+ // Configure memory initializer path (if needed)
95
+ if (typeof window !== 'undefined') {
96
+ (window as any).Mp3LameEncoderConfig = {
97
+ memoryInitializerPrefixURL: '/path/to/'
98
+ };
99
+ }
100
+
101
+ const audioContext = new AudioContext();
102
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
103
+
104
+ const recorder = new WebAudioRecorderMp3(
105
+ audioContext,
106
+ {},
107
+ { bitrate: 192 } // MP3 bitrate in kbps
108
+ );
109
+
110
+ await recorder.start(stream);
111
+ const blob = await recorder.stop();
112
+ ```
113
+
114
+ ## API Reference
115
+
116
+ ### WebAudioRecorder (Base Class)
117
+
118
+ Base class for all recorders. Usually you'll use the specific format recorders instead.
119
+
120
+ #### Constructor
121
+
122
+ ```typescript
123
+ constructor(
124
+ audioContext: AudioContext,
125
+ encoder: AudioEncoder,
126
+ options?: RecorderOptions
127
+ )
128
+ ```
129
+
130
+ #### Methods
131
+
132
+ - `start(stream: MediaStream): Promise<void>` - Start recording
133
+ - `stop(mimeType?: string): Promise<Blob>` - Stop recording and get the audio blob
134
+ - `cancel(): void` - Cancel current recording
135
+ - `getStatus(): RecorderStatus` - Get current recorder status
136
+ - `setOnDataAvailable(callback: DataAvailableCallback | null): void` - Set data available callback
137
+ - `setOnComplete(callback: CompleteCallback | null): void` - Set completion callback
138
+ - `setOnError(callback: ErrorCallback | null): void` - Set error callback
139
+ - `cleanup(): void` - Clean up resources
140
+
141
+ ### WebAudioRecorderWav
142
+
143
+ WAV format recorder. No external dependencies required.
144
+
145
+ ```typescript
146
+ const recorder = new WebAudioRecorderWav(audioContext, options?);
147
+ ```
148
+
149
+ ### WebAudioRecorderOgg
150
+
151
+ OGG Vorbis format recorder. Requires OggVorbisEncoder.min.js and .mem files.
152
+
153
+ ```typescript
154
+ const recorder = new WebAudioRecorderOgg(
155
+ audioContext,
156
+ options?,
157
+ { quality?: number } // -0.1 to 1.0, default: 0.5
158
+ );
159
+ ```
160
+
161
+ ### WebAudioRecorderMp3
162
+
163
+ MP3 format recorder. Requires Mp3LameEncoder.min.js and .mem files.
164
+
165
+ ```typescript
166
+ const recorder = new WebAudioRecorderMp3(
167
+ audioContext,
168
+ options?,
169
+ { bitrate?: number } // in kbps, default: 128
170
+ );
171
+ ```
172
+
173
+ ### Types
174
+
175
+ ```typescript
176
+ interface RecorderOptions {
177
+ sampleRate?: number; // Default: audioContext.sampleRate
178
+ numChannels?: number; // Default: 2 (stereo)
179
+ bufferSize?: number; // Default: 4096
180
+ onDataAvailable?: (event: DataAvailableEvent) => void;
181
+ onComplete?: (event: CompleteEvent) => void;
182
+ onError?: (event: ErrorEvent) => void;
183
+ }
184
+
185
+ enum RecorderStatus {
186
+ INACTIVE = 'inactive',
187
+ RECORDING = 'recording',
188
+ PAUSED = 'paused',
189
+ PROCESSING = 'processing',
190
+ COMPLETE = 'complete',
191
+ ERROR = 'error'
192
+ }
193
+ ```
194
+
195
+ ## Setup for OGG and MP3
196
+
197
+ OGG and MP3 encoders require external JavaScript files compiled via Emscripten. You need to:
198
+
199
+ 1. Copy the encoder files to your project:
200
+ - `OggVorbisEncoder.min.js` and `OggVorbisEncoder.min.js.mem`
201
+ - `Mp3LameEncoder.min.js` and `Mp3LameEncoder.min.js.mem`
202
+
203
+ 2. These files are included in the `lib/` directory of this package.
204
+
205
+ 3. Load the encoder scripts before creating recorders:
206
+
207
+ ```typescript
208
+ // For OGG
209
+ await loadOggVorbisEncoder('/path/to/OggVorbisEncoder.min.js');
210
+
211
+ // For MP3
212
+ await loadMp3LameEncoder('/path/to/Mp3LameEncoder.min.js');
213
+ ```
214
+
215
+ 4. Configure memory initializer path if needed:
216
+
217
+ ```typescript
218
+ // For OGG
219
+ window.OggVorbisEncoderConfig = {
220
+ memoryInitializerPrefixURL: '/path/to/'
221
+ };
222
+
223
+ // For MP3
224
+ window.Mp3LameEncoderConfig = {
225
+ memoryInitializerPrefixURL: '/path/to/'
226
+ };
227
+ ```
228
+
229
+ ## Browser Support
230
+
231
+ - Chrome/Edge: Full support
232
+ - Firefox: Full support
233
+ - Safari: Full support (may require user gesture for audio context)
234
+ - Opera: Full support
235
+
236
+ ## License
237
+
238
+ - TypeScript code: MIT License
239
+ - OGG Vorbis encoder: Xiph BSD License
240
+ - MP3 LAME encoder: LGPL License
241
+
242
+ See LICENSE file for details.
243
+
244
+ ## Credits
245
+
246
+ This is a TypeScript port of:
247
+ - [web-audio-recorder-js](https://github.com/higuma/web-audio-recorder-js) by higuma
248
+ - [ogg-vorbis-encoder-js](https://github.com/higuma/ogg-vorbis-encoder-js) by higuma
249
+
250
+ ## Contributing
251
+
252
+ Contributions are welcome! Please feel free to submit a Pull Request.
253
+
254
+ ## Changelog
255
+
256
+ ### 1.0.0
257
+
258
+ - Initial TypeScript port
259
+ - Full type definitions
260
+ - Support for WAV, OGG, and MP3 formats
261
+ - Modern build system with ESM, CJS, and UMD outputs
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Classe base WebAudioRecorder para gravação de áudio
3
+ *
4
+ * @module core/WebAudioRecorder
5
+ */
6
+ import { RecorderOptions, RecorderStatus, DataAvailableCallback, CompleteCallback, ErrorCallback, AudioEncoder } from './types';
7
+ /**
8
+ * Classe principal para gravação de áudio usando Web Audio API
9
+ */
10
+ export declare class WebAudioRecorder {
11
+ protected audioContext: AudioContext | null;
12
+ protected sourceNode: MediaStreamAudioSourceNode | null;
13
+ protected scriptProcessor: ScriptProcessorNode | null;
14
+ protected encoder: AudioEncoder | null;
15
+ protected stream: MediaStream | null;
16
+ protected status: RecorderStatus;
17
+ protected sampleRate: number;
18
+ protected numChannels: number;
19
+ protected bufferSize: number;
20
+ protected startTime: number;
21
+ protected onDataAvailableCallback: DataAvailableCallback | null;
22
+ protected onCompleteCallback: CompleteCallback | null;
23
+ protected onErrorCallback: ErrorCallback | null;
24
+ /**
25
+ * Cria uma instância do WebAudioRecorder
26
+ *
27
+ * @param audioContext - Contexto de áudio Web Audio API
28
+ * @param encoder - Encoder de áudio a ser usado
29
+ * @param options - Opções de configuração do recorder
30
+ */
31
+ constructor(audioContext: AudioContext, encoder: AudioEncoder, options?: RecorderOptions);
32
+ /**
33
+ * Inicia a gravação de áudio
34
+ *
35
+ * @param stream - Stream de mídia a ser gravado
36
+ * @returns Promise que resolve quando a gravação inicia
37
+ */
38
+ start(stream: MediaStream): Promise<void>;
39
+ /**
40
+ * Para a gravação e finaliza o arquivo de áudio
41
+ *
42
+ * @param mimeType - Tipo MIME do arquivo (padrão: baseado no encoder)
43
+ * @returns Promise que resolve com o Blob do áudio gravado
44
+ */
45
+ stop(mimeType?: string): Promise<Blob>;
46
+ /**
47
+ * Cancela a gravação atual
48
+ */
49
+ cancel(): void;
50
+ /**
51
+ * Obtém o status atual do recorder
52
+ *
53
+ * @returns Status atual
54
+ */
55
+ getStatus(): RecorderStatus;
56
+ /**
57
+ * Define callback para quando dados estão disponíveis
58
+ *
59
+ * @param callback - Função callback
60
+ */
61
+ setOnDataAvailable(callback: DataAvailableCallback | null): void;
62
+ /**
63
+ * Define callback para quando gravação é completada
64
+ *
65
+ * @param callback - Função callback
66
+ */
67
+ setOnComplete(callback: CompleteCallback | null): void;
68
+ /**
69
+ * Define callback para quando ocorre erro
70
+ *
71
+ * @param callback - Função callback
72
+ */
73
+ setOnError(callback: ErrorCallback | null): void;
74
+ /**
75
+ * Trata erros e chama callback de erro
76
+ *
77
+ * @param error - Erro ocorrido
78
+ */
79
+ protected handleError(error: Error): void;
80
+ /**
81
+ * Limpa recursos e reseta o recorder
82
+ */
83
+ cleanup(): void;
84
+ }
85
+ //# sourceMappingURL=WebAudioRecorder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebAudioRecorder.d.ts","sourceRoot":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3B;;;;OAIG;IACH,kBAAkB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,IAAI,GAAG,IAAI;IAIhE;;;;OAIG;IACH,aAAa,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI,GAAG,IAAI;IAItD;;;;OAIG;IACH,UAAU,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI,GAAG,IAAI;IAIhD;;;;OAIG;IACH,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAWzC;;OAEG;IACH,OAAO,IAAI,IAAI;CAMhB"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Tipos e interfaces principais para WebAudioRecorder
3
+ */
4
+ /**
5
+ * Formatos de áudio suportados
6
+ */
7
+ export declare enum AudioFormat {
8
+ WAV = "wav",
9
+ OGG = "ogg",
10
+ MP3 = "mp3"
11
+ }
12
+ /**
13
+ * Status do recorder
14
+ */
15
+ export declare enum RecorderStatus {
16
+ INACTIVE = "inactive",
17
+ RECORDING = "recording",
18
+ PAUSED = "paused",
19
+ PROCESSING = "processing",
20
+ COMPLETE = "complete",
21
+ ERROR = "error"
22
+ }
23
+ /**
24
+ * Opções de configuração do recorder
25
+ */
26
+ export interface RecorderOptions {
27
+ /** Taxa de amostragem em Hz (padrão: 44100) */
28
+ sampleRate?: number;
29
+ /** Número de canais (1 = mono, 2 = estéreo, padrão: 2) */
30
+ numChannels?: number;
31
+ /** Tamanho do buffer em frames (padrão: 4096) */
32
+ bufferSize?: number;
33
+ /** Callback quando dados estão disponíveis */
34
+ onDataAvailable?: (event: DataAvailableEvent) => void;
35
+ /** Callback quando gravação é completada */
36
+ onComplete?: (event: CompleteEvent) => void;
37
+ /** Callback quando ocorre erro */
38
+ onError?: (event: ErrorEvent) => void;
39
+ }
40
+ /**
41
+ * Evento de dados disponíveis
42
+ */
43
+ export interface DataAvailableEvent {
44
+ /** Dados de áudio como Blob */
45
+ data: Blob;
46
+ /** Timestamp do evento */
47
+ timecode: number;
48
+ }
49
+ /**
50
+ * Evento de gravação completa
51
+ */
52
+ export interface CompleteEvent {
53
+ /** Blob final do áudio gravado */
54
+ blob: Blob;
55
+ /** URL do objeto para reprodução */
56
+ url: string;
57
+ }
58
+ /**
59
+ * Evento de erro
60
+ */
61
+ export interface ErrorEvent {
62
+ /** Mensagem de erro */
63
+ message: string;
64
+ /** Erro original (se houver) */
65
+ error?: Error;
66
+ }
67
+ /**
68
+ * Interface para encoders de áudio
69
+ */
70
+ export interface AudioEncoder {
71
+ /** Codificar buffers de áudio */
72
+ encode(buffers: Float32Array[]): void;
73
+ /** Finalizar encoding e obter Blob */
74
+ finish(mimeType?: string): Blob;
75
+ /** Cancelar encoding */
76
+ cancel(): void;
77
+ }
78
+ /**
79
+ * Configuração para encoder OGG Vorbis
80
+ */
81
+ export interface OggVorbisOptions {
82
+ /** Qualidade Vorbis (-0.1 a 1.0, padrão: 0.5) */
83
+ quality?: number;
84
+ }
85
+ /**
86
+ * Configuração para encoder MP3
87
+ */
88
+ export interface Mp3Options {
89
+ /** Bitrate em kbps (padrão: 128) */
90
+ bitrate?: number;
91
+ }
92
+ /**
93
+ * Configuração para encoder WAV
94
+ */
95
+ export interface WavOptions {
96
+ }
97
+ /**
98
+ * Callback para eventos de dados
99
+ */
100
+ export type DataAvailableCallback = (event: DataAvailableEvent) => void;
101
+ /**
102
+ * Callback para eventos de conclusão
103
+ */
104
+ export type CompleteCallback = (event: CompleteEvent) => void;
105
+ /**
106
+ * Callback para eventos de erro
107
+ */
108
+ export type ErrorCallback = (event: ErrorEvent) => void;
109
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,oBAAY,WAAW;IACrB,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,QAAQ;CACZ;AAED;;GAEG;AACH,oBAAY,cAAc;IACxB,QAAQ,aAAa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ACjD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,oCAAoC;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;CAE1B;AAED;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Wrapper TypeScript para Mp3LameEncoder (Emscripten)
3
+ *
4
+ * @module encoders/Mp3LameEncoder
5
+ */
6
+ import { AudioEncoder, Mp3Options } from '../core/types';
7
+ /**
8
+ * Wrapper para o encoder MP3 LAME compilado via Emscripten
9
+ */
10
+ export declare class Mp3LameEncoderWrapper implements AudioEncoder {
11
+ private encoder;
12
+ private sampleRate;
13
+ private numChannels;
14
+ private bitrate;
15
+ /**
16
+ * Cria uma instância do encoder MP3 LAME
17
+ *
18
+ * @param sampleRate - Taxa de amostragem em Hz
19
+ * @param numChannels - Número de canais
20
+ * @param options - Opções do encoder MP3
21
+ */
22
+ constructor(sampleRate: number, numChannels: number, options?: Mp3Options);
23
+ /**
24
+ * Codifica buffers de áudio
25
+ *
26
+ * @param buffers - Array de buffers Float32Array, um por canal
27
+ */
28
+ encode(buffers: Float32Array[]): void;
29
+ /**
30
+ * Finaliza o encoding e retorna o Blob MP3
31
+ *
32
+ * @param mimeType - Tipo MIME (padrão: 'audio/mpeg')
33
+ * @returns Blob contendo o arquivo MP3
34
+ */
35
+ finish(mimeType?: string): Blob;
36
+ /**
37
+ * Cancela o encoding
38
+ */
39
+ cancel(): void;
40
+ }
41
+ /**
42
+ * Função helper para carregar o script Mp3LameEncoder
43
+ *
44
+ * @param scriptUrl - URL do script Mp3LameEncoder.min.js
45
+ * @returns Promise que resolve quando o script é carregado
46
+ */
47
+ export declare function loadMp3LameEncoder(scriptUrl: string): Promise<void>;
48
+ //# sourceMappingURL=Mp3LameEncoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Mp3LameEncoder.d.ts","sourceRoot":"","sources":["../../src/encoders/Mp3LameEncoder.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAczD;;GAEG;AACH,qBAAa,qBAAsB,YAAW,YAAY;IACxD,OAAO,CAAC,OAAO,CAAuC;IACtD,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAS;IAExB;;;;;;OAMG;gBACS,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe;IAc7E;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,IAAI;IAYrC;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,GAAE,MAAqB,GAAG,IAAI;IAQ7C;;OAEG;IACH,MAAM,IAAI,IAAI;CAMf;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqEnE"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Wrapper TypeScript para OggVorbisEncoder (Emscripten)
3
+ *
4
+ * @module encoders/OggVorbisEncoder
5
+ */
6
+ import { AudioEncoder, OggVorbisOptions } from '../core/types';
7
+ /**
8
+ * Wrapper para o encoder OGG Vorbis compilado via Emscripten
9
+ */
10
+ export declare class OggVorbisEncoderWrapper implements AudioEncoder {
11
+ private encoder;
12
+ private sampleRate;
13
+ private numChannels;
14
+ private quality;
15
+ /**
16
+ * Cria uma instância do encoder OGG Vorbis
17
+ *
18
+ * @param sampleRate - Taxa de amostragem em Hz
19
+ * @param numChannels - Número de canais
20
+ * @param options - Opções do encoder OGG
21
+ */
22
+ constructor(sampleRate: number, numChannels: number, options?: OggVorbisOptions);
23
+ /**
24
+ * Codifica buffers de áudio
25
+ *
26
+ * @param buffers - Array de buffers Float32Array, um por canal
27
+ */
28
+ encode(buffers: Float32Array[]): void;
29
+ /**
30
+ * Finaliza o encoding e retorna o Blob OGG
31
+ *
32
+ * @param mimeType - Tipo MIME (padrão: 'audio/ogg')
33
+ * @returns Blob contendo o arquivo OGG
34
+ */
35
+ finish(mimeType?: string): Blob;
36
+ /**
37
+ * Cancela o encoding
38
+ */
39
+ cancel(): void;
40
+ }
41
+ /**
42
+ * Função helper para carregar o script OggVorbisEncoder
43
+ *
44
+ * @param scriptUrl - URL do script OggVorbisEncoder.min.js
45
+ * @returns Promise que resolve quando o script é carregado
46
+ */
47
+ export declare function loadOggVorbisEncoder(scriptUrl: string): Promise<void>;
48
+ //# sourceMappingURL=OggVorbisEncoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OggVorbisEncoder.d.ts","sourceRoot":"","sources":["../../src/encoders/OggVorbisEncoder.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAc/D;;GAEG;AACH,qBAAa,uBAAwB,YAAW,YAAY;IAC1D,OAAO,CAAC,OAAO,CAAyC;IACxD,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAS;IAExB;;;;;;OAMG;gBACS,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB;IAcnF;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,IAAI;IAYrC;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,GAAE,MAAoB,GAAG,IAAI;IAQ5C;;OAEG;IACH,MAAM,IAAI,IAAI;CAMf;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqErE"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Encoder WAV para áudio
3
+ *
4
+ * @module encoders/WavAudioEncoder
5
+ */
6
+ import { AudioEncoder } from '../core/types';
7
+ /**
8
+ * Encoder WAV simples que cria arquivos WAV a partir de buffers de áudio
9
+ */
10
+ export declare class WavAudioEncoder implements AudioEncoder {
11
+ private sampleRate;
12
+ private numChannels;
13
+ private buffers;
14
+ /**
15
+ * Cria uma instância do encoder WAV
16
+ *
17
+ * @param sampleRate - Taxa de amostragem em Hz
18
+ * @param numChannels - Número de canais (1 = mono, 2 = estéreo)
19
+ */
20
+ constructor(sampleRate: number, numChannels: number);
21
+ /**
22
+ * Codifica buffers de áudio
23
+ *
24
+ * @param buffers - Array de buffers Float32Array, um por canal
25
+ */
26
+ encode(buffers: Float32Array[]): void;
27
+ /**
28
+ * Finaliza o encoding e retorna o Blob WAV
29
+ *
30
+ * @param mimeType - Tipo MIME (padrão: 'audio/wav')
31
+ * @returns Blob contendo o arquivo WAV
32
+ */
33
+ finish(mimeType?: string): Blob;
34
+ /**
35
+ * Cancela o encoding e limpa os buffers
36
+ */
37
+ cancel(): void;
38
+ /**
39
+ * Escreve string no DataView
40
+ *
41
+ * @param view - DataView
42
+ * @param offset - Offset inicial
43
+ * @param string - String a escrever
44
+ */
45
+ private writeString;
46
+ }
47
+ //# sourceMappingURL=WavAudioEncoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WavAudioEncoder.d.ts","sourceRoot":"","sources":["../../src/encoders/WavAudioEncoder.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C;;GAEG;AACH,qBAAa,eAAgB,YAAW,YAAY;IAClD,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAwB;IAEvC;;;;;OAKG;gBACS,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;IAMnD;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,IAAI;IASrC;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,GAAE,MAAoB,GAAG,IAAI;IA2F5C;;OAEG;IACH,MAAM,IAAI,IAAI;IAId;;;;;;OAMG;IACH,OAAO,CAAC,WAAW;CAKpB"}