@@ -38,7 +38,7 @@ const flac = await encode.flac(channelData, { sampleRate: 44100 });
3838const opus = await encode .opus (channelData, { sampleRate: 48000 , bitrate: 96 });
3939```
4040
41- ### Stream encoding
41+ ### Chunked encoding
4242
4343Call with just options (no data) to create a streaming encoder:
4444
@@ -49,11 +49,21 @@ const enc = await encode.mp3({ sampleRate: 44100, bitrate: 128 });
4949
5050const a = await enc (chunk1); // Uint8Array
5151const b = await enc (chunk2);
52- const c = await enc (); // end of stream — flush + free
52+ const c = await enc (null ); // end of stream — flush + free
5353
5454// explicit control: enc.flush(), enc.free()
5555```
5656
57+ ### TransformStream
58+
59+ ``` js
60+ import encodeStream from ' encode-audio/stream' ;
61+
62+ audioSource
63+ .pipeThrough (encodeStream (' mp3' , { sampleRate: 44100 , bitrate: 128 }))
64+ .pipeTo (destination);
65+ ```
66+
5767### Options
5868
5969| Option | Description | Applies to |
@@ -66,17 +76,6 @@ const c = await enc(); // end of stream — flush + free
6676| ` compression ` | FLAC compression level 0–8 | flac |
6777| ` application ` | ` 'audio' ` , ` 'voip' ` , or ` 'lowdelay' ` | opus |
6878
69- ### Custom encoders
70-
71- The ` encode ` registry is extensible:
72-
73- ``` js
74- import encode from ' encode-audio' ;
75- encode .myformat = Object .assign (
76- async (data , opts ) => { /* ... */ },
77- { stream: async (opts ) => ({ encode : chunk => ... , free () {} }) }
78- );
79- ```
8079
8180## See also
8281
0 commit comments