0
const speaker = new Speaker({
          channels: 2,
          bitDepth: 16,
          sampleRate: 44100,
          device: null,
        });

stream.pipe(speaker);

I need it for break playing sound. Stream is instance of Readable.

1 Answers1

0

stream.pipeline which claims to handle “forwarding errors and properly cleaning up and provide a callback when the pipeline is complete.”

Syntax

stream.pipeline(...streams, callback)
  • …streams: These are two or more streams which are to be piped together.
  • callback: This function is called when the pipeline is fully done and it shows an ‘error’ if the pipeline is not accomplished.

Here is a link to documentation.

Deep Kakkar
  • 5,831
  • 4
  • 39
  • 75
  • FYI, `stream.pipeline()` does not fully handle errors properly. Here's a quote from the doc: ***stream.pipeline() leaves dangling event listeners on the streams after the callback has been invoked. In the case of reuse of streams after failure, this can cause event listener leaks and swallowed errors.*** – jfriend00 Apr 20 '20 at 04:46
  • I'm also not sure how this answers the question that was asked. – jfriend00 Apr 20 '20 at 04:49
  • That's up to you. Do you think you answered the question they asked? – jfriend00 Apr 20 '20 at 05:00