crucialfelix / supercolliderjs

The JavaScript client library for SuperCollider
https://crucialfelix.github.io/supercolliderjs/
MIT License
470 stars 40 forks source link

Streaming audio with http api request #77

Open VictorKolb opened 4 years ago

VictorKolb commented 4 years ago

Hello! Thanks for cool library! I have newbie question: Is it possible to streaming audio from supercolliderjs with http api request?

If I have simple mp3 file I can do something like this:

app.get("/api/audiofile", (req, res) => {
    const filePath = path.resolve("example/file.mp3");
    const stat = fs.statSync(filePath);

    res.writeHead(200, {
        "Content-Type": "audio/mpeg",
        "Content-Length": stat.size,
    });

    const readStream = fs.createReadStream(filePath);
    readStream.pipe(res);
});

I trying naudiodon, but I guess it not right solution

crucialfelix commented 4 years ago

It depends on how you are going to host the project. You can run scsynth in a docker container and stream audio out.

Here is one example: https://github.com/maxhawkins/sc_radio

But I think we need a new up to date one.

If I had the time I would set up a Dockerfile that runs supercollider.js with streaming. That could support many listeners, one stereo broadcast channel.

It may be possible to do it with AWS lambda (15 minutes max execution) in which case each visitor gets their own scsynth. Initially more complicated to solve.

VictorKolb commented 4 years ago

@crucialfelix amazing! It is what I need. I'll try to figure it out. Thanks!

VictorKolb commented 4 years ago

@crucialfelix so, apparently Node js can't streaming audio from sound cart to api. Do I understand correctly that I can't without Icecast and Darkice? Let's say I want to stream docker container audio out. Can you point in the direction of for google, please?

crucialfelix commented 4 years ago

Node here is starting the scsynth process and sending it osc messages. Those messages are to load sounds, play, modulate, stop, filter, efx, sequencing etc.

The sound engine plays on a device which icecast (and other sound streaming apps) can pipe to an MP3 stream. Clients connect to that over http.

Make sense?

VictorKolb commented 4 years ago

@crucialfelix hm.I think it's become clearer. Thank you!