-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayAudioFiles.js
35 lines (27 loc) · 999 Bytes
/
playAudioFiles.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
if (process.env.ENV !== 'prod') {
require('dotenv').config()
}
const { spawn, exec } = require('child_process');
const baseUrl = './processed'
const MIN_VALUE = 1;
const MAX_VALUE = 2;
let channels = Array.from(new Array(+process.env.CHANNELS), (x, i) => i);
const launchCommand = c => {
let commandToLaunch = command(c);
console.log(`CHANNEL ${c} - ${commandToLaunch}`);
exec(commandToLaunch, (e, stdout, stderr) => {
if (e instanceof Error) {
console.error(e);
throw e;
}
stderr && console.error('stderr ', stderr);
launchCommand(c);
});
}
const command = c => {
//let audioFile = `${baseUrl}/${c}/${Math.floor(Math.random() * MAX_VALUE) + MIN_VALUE}.wav && sleep ${Math.floor(Math.random() * 7)}`;
let audioFile = `${baseUrl}/${c}/${Math.floor(Math.random() * MAX_VALUE) + MIN_VALUE}.wav`;
//return `echo ${audioFile}`;
return `aplay ${audioFile}`;
}
channels.forEach(c => launchCommand(c));