Stop pause and search for audio stream

1) I use node -speaker and pause-stream as follows:

        var mp3Stream = fs.createReadStream(__dirname + '/sounds/' + filename);
        mp3Stream.pipe(new Lame.Decoder()).pipe(speaker);

        // ...
        function pause () { 
          if (isPlaying) {

              mp3Stream.pipe(pauseStream.pause());
              isPlaying = false;
          }
        }

and receive the audio stream is suspended only a few seconds after a pause (). How to use audio streams to prevent such buffering?

2) I switch the tracks as follows:

function play(params) { 

        if (isPlaying) {

            speaker.end();
            speaker = new Speaker({
                channels: 2,          // 2 channels
                bitDepth: 16,         // 16-bit samples
                sampleRate: 44100     // 44,100 Hz sample rate
            });
        }

        mp3Stream = fs.createReadStream(__dirname + '/sounds/' + params.filename);
        mp3Stream.pipe(new Lame.Decoder()).pipe(speaker);

        isPlaying = true;
}

Everything is fine? I am afraid that I will have memory leaks.

3) Is there an easy way to search for sound buffers?

Thank!

+4
source share

Source: https://habr.com/ru/post/1535757/


All Articles