I am trying to play a random amount of random audio files over PIFM using node.js
// A function that will let me call and play one random audio file.
function audio1(){
var child_process = require("child_process") //calls child process
//These are my 9 audio wavs that will play one after the other on pi2fm
var ran1 = child_process.execSync("sudo -E /Path/to/pi2fm audio1.wav 103.50");
var ran2 = child_process.execSync("sudo -E /Path/to/pi2fm audio2.wav 103.50");
var ran3 = child_process.execSync("sudo -E /Path/to/pi2fm audio3.wav 103.50");
var ran4 = child_process.execSync("sudo -E /Path/to/pi2fm audio4.wav 103.50");
var ran5 = child_process.execSync("sudo -E /Path/to/pi2fm audio5.wav 103.50");
var ran6 = child_process.execSync("sudo -E /Path/to/pi2fm audio6.wav 103.50");
var ran7 = child_process.execSync("sudo -E /Path/to/pi2fm audio7.wav 103.50");
var ran8 = child_process.execSync("sudo -E /Path/to/pi2fm audio8.wav 103.50");
var ran9 = child_process.execSync("sudo -E /Path/to/pi2fm audio9.wav 103.50");
function randomFrom(array) {return array[Math.floor(Math.random() * array.length)];} // this creates a function (randomFrom()) that selects a random variable in array
var ranAudio = [ran1, ran2, ran3, ran4, ran5, ran6, ran7, ran8 ,ran9]; //this is my array of variable containg execution of audio on Pi2fm
randomFrom(ranAudio).call(); // feeds ranAudio to randomFrom()
}
//calls audio1();
audio1();
with the above code the files are playing one after another (I don't want this). And then when it gets to randomFrom() where I would expect one of the files to play randomly I am getting the following error:
randomFrom(ranAudio).call();
^
TypeError: randomFrom(...).call is not a function
To clarify, I just want a random amount of audio files (1- 9) to play, however, so far I can not get even one random file to play.
Any suggestions, appreciated etc.