audio-sink

Sink or tap audio stream data

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
audio-sink
411.1.67 years ago8 years agoMinified + gzip package size for audio-sink in KB

Readme

audio-sink Build Status stable
Triggers an event for received audio chunk and releases the data. If piped to somewhere, it turns into a pass-throught stream. That way, it is through2-sink and tap-stream in one. Use as a fast replacement for audio-speaker or audio-render. Can function as a pressure controller. See example.

Usage

npm install audio-sink

Direct

```js const Sink = require('audio-sink/direct'); let sink = Sink((data, cb) => {
console.log(data);
setTimeout(cb, 100);
}); //log data and invoke cb after 100ms sink(buffer, (err, buffer) => { }); ```

Pull-stream

```js const pull = require('pull-stream/pull'); const sink = require('audio-sink/pull'); const generator = require('audio-generator/pull'); //stream generated data to sink with pressure control pull(
generator(time => Math.sin(time * Math.PI * 2 * 440)),
sink((data, cb) => {
//end stream if needed
if (tooLate) return cb(true);
console.log(data);
setTimeout(cb, 100);
});
); ```

Stream

```js var Gen = require('audio-generator/stream'); var Sink = require('audio-sink/stream'); Gen(function (time) {
return time ? 0 : 1;
}) .pipe(Sink(function (data, cb) {
console.log('This sink is a pass-through with 10ms throttling ', data.length);
setTimeout(cb, 10);
})) .pipe(Sink(function (data) {
console.log('This sink gets the data and releases it ', data.length);
})); ```

Related

stream-sink — universal stream sink.
through2-sink — triggers an event for the data chunk, but does not pass data through.
tap-stream — triggers callback for the passed through data, but does not release data.