Downloads a random 15 second music file from https://tones.wolfram.com/generate.
As a shell script:
npx get-random-music
Or in JavaScript:
const fs = require("fs");
const path = require("path");
const downloadRandomMusic = require("get-random-music");
const outPath = path.join(__dirname, "random-music.mp3");
const outStream = fs.createWriteStream(outPath);
const downloadStream = await downloadRandomMusic().then((res) => res.data);
await new Promise((resolve, reject) => {
downloadStream.pipe(outStream);
downloadStream.on("error", (error) => {
console.error(error);
downloadStream.close();
reject();
});
downloadStream.on("close", () => {
console.log("Complete");
resolve();
});
});