diff --git a/js-programming/bytebeat-render.js b/js-programming/bytebeat-render.js index 8714fef..342d72f 100644 --- a/js-programming/bytebeat-render.js +++ b/js-programming/bytebeat-render.js @@ -72,7 +72,7 @@ const random_choice = choices => choices[Math.floor(Math.random() * choices.leng const randomFileNameAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-" -const generateRandomFileName = () => { +const generateRandomFilePath = () => { let res = tmpdir() + "/" + basename(__filename) + "_" for (let i = 0; i < 64; i++) res += random_choice(randomFileNameAlphabet) @@ -81,8 +81,8 @@ const generateRandomFileName = () => { let t = 0 -let fileName = generateRandomFileName() -writeFileSync(fileName, Buffer.alloc(0)) +let filePath = generateRandomFilePath() +writeFileSync(filePath, Buffer.alloc(0)) // the loop of sequential file writing, created to ease load on RAM for (let buffer = 0; t < PRODUCT; buffer++) { @@ -106,12 +106,12 @@ for (let buffer = 0; t < PRODUCT; buffer++) { audioData = truncatedArray } - appendFileSync(fileName, Buffer.from(audioData.buffer)) + appendFileSync(filePath, Buffer.from(audioData.buffer)) audioData = null } execSync( `ffmpeg -f u8 -ar ${FINAL_SAMPLE_RATE} -ac ${CHANNELS} ` + - `-i ${fileName} output_${+new Date()}.wav`) -unlinkSync(fileName) + `-i ${filePath} output_${+new Date()}.wav`) +unlinkSync(filePath)