Let's assume I go to a page where audio gets played. Is there any way to expose and capture the audio stream coming from this puppeteer page? I don't want to simply save it but instead have access to the stream which I can constantly pipe throughout other stuff (for example to a server using the discord api)
There's already a similar issue on the official GitHub repo: startScreencast feature?
But I simply want to have access to the audio pipeline of the page instance (preferably a stream). Is there any way to accomplish this?
I had the same problem and therefore developed a npm package puppeteer-stream. Be aware that this will only work in headful mode, because extension aren't supported in headless mode. I also made an example how you can stream to discord.
You can run code in the target page like so:
await page.evaluate(() => {
var audio = document.getElementById('audio');
audio.onplay = function() {
// Set the source of one <audio> element to be a stream from another.
var stream = audio.captureStream();
// This is your audio stream object...
};
});
More info:
page.evaluate() spec
Capture a MediaStream From a Canvas, Video or Audio Element
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With