You want to use p5.js because you are using node, right? You want to use p5.js sound as you want to save your data using a sound file format, right?
Not sure if p5.js can do it:
reference | p5.js
MediaDevices: enumerateDevices() method - Web APIs | MDN
You will be limited by the Sound API, which defines your input sources. A couple of options is to save the file as raw binary and convert it manually in a second step. As an alternative, I believe you could use Minim and Processing java. Now, I don’t think I have tried this before but I think it would be possible. For this, there is a need to “roll-up one’s sleeves” to get it done.
In case you are wondering if you can mix node and Processing Java, the answer is sort of yes. You run Processing from node using exec()
, so you are executing a Processing sketch in the background. There are some other ideas following this approach. For this, it is important to know more about your project. Do you want to play the sound as it arrives or is it enough to store it and save it as shown in the P5.sound’s recorder example? In this example, the data is transfer to another class (stored in memory) as saved at the end.
Before you follow this rabbit-hole, maybe do a quick search to see if there is a js library available that could do this for you or even if there is a program with a CLI interface that will convert your raw data into a sound file.
Kf