-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio-encode.d.ts
More file actions
72 lines (64 loc) · 2.28 KB
/
audio-encode.d.ts
File metadata and controls
72 lines (64 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
type AudioInput = Float32Array[] | Float32Array | { numberOfChannels: number; getChannelData(i: number): Float32Array };
export interface EncodeOptions {
/** Output sample rate (required). */
sampleRate: number;
/** Output channel count. */
channels?: number;
/** Target bitrate in kbps (lossy). */
bitrate?: number;
/** Quality 0-10 (VBR, format-specific). */
quality?: number;
/** Bit depth: 16|32 for wav, 16|24 for aiff/flac. */
bitDepth?: number;
/** FLAC compression level 0-8. */
compression?: number;
/** Opus application: 'audio', 'voip', 'lowdelay'. */
application?: string;
[key: string]: any;
}
export interface StreamEncoder {
/** Encode a chunk of audio. */
(channelData: AudioInput): Promise<Uint8Array>;
/** Flush remaining data, finalize, and free resources. */
(): Promise<Uint8Array>;
/** Flush without freeing. */
flush(): Promise<Uint8Array>;
/** Free resources without flushing. */
free(): void;
}
export interface FormatEncoder {
/** Whole-file encode. */
(channelData: AudioInput, opts: EncodeOptions): Promise<Uint8Array>;
/** Chunked encode from async iterable. */
(source: AsyncIterable<AudioInput>, opts: EncodeOptions): AsyncGenerator<Uint8Array>;
/** Create streaming encoder. */
(opts: EncodeOptions): Promise<StreamEncoder>;
}
declare const encode: {
/** Whole-file encode. */
(format: string, channelData: AudioInput, opts: EncodeOptions): Promise<Uint8Array>;
/** Chunked encode from async iterable. */
(format: string, source: AsyncIterable<AudioInput>, opts: EncodeOptions): AsyncGenerator<Uint8Array>;
/** Create streaming encoder. */
(format: string, opts: EncodeOptions): Promise<StreamEncoder>;
wav: FormatEncoder;
aiff: FormatEncoder;
mp3: FormatEncoder;
ogg: FormatEncoder;
flac: FormatEncoder;
opus: FormatEncoder;
[format: string]: FormatEncoder;
};
export default encode;
/** Chunked encode from async iterable. */
export function encodeChunked(
source: AsyncIterable<AudioInput>,
format: string,
opts: EncodeOptions
): AsyncGenerator<Uint8Array>;
/** Wrap codec callbacks into a StreamEncoder with lifecycle management. */
export function streamEncoder(
onEncode: (channels: Float32Array[]) => Uint8Array | Promise<Uint8Array>,
onFlush?: (() => Uint8Array | Promise<Uint8Array>) | null,
onFree?: (() => void) | null
): StreamEncoder;