1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2024-11-10 06:42:02 +05:30

bytebeat-render.js: rename *Name to *Path

This commit is contained in:
Intel A80486DX2-66 2024-01-05 20:12:57 +03:00
parent ab8843ee14
commit 0eaced9cde
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

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