|
import { exec } from "child_process"; |
|
import { promisify } from "util"; |
|
|
|
const execAsync = promisify(exec); |
|
|
|
async function addMilitaryRadioEffect( |
|
inputFile: string, |
|
outputFile: string |
|
): Promise<void> { |
|
try { |
|
|
|
const { stdout: sampleRate } = await execAsync(`soxi -r "${inputFile}"`); |
|
const rate = sampleRate.trim(); |
|
|
|
|
|
const noiseCmd = `sox -r ${rate} -n noise.wav synth 10 whitenoise vol 0.15`; |
|
await execAsync(noiseCmd); |
|
|
|
|
|
const crackleCmd = `sox -r ${rate} -n crackle.wav synth 10 whitenoise band -n 300 2700 vol 0.1`; |
|
await execAsync(crackleCmd); |
|
|
|
|
|
const voiceCmd = `sox "${inputFile}" voice_mod.wav \ |
|
gain -n -1 \ |
|
sinc -n 4096 -b 48 300 \ |
|
sinc -n 4096 -b 48 -2700 \ |
|
compand 0.05,0.2 6:-70,-60,-20 -8 -90 0.1 \ |
|
overdrive 20 \ |
|
gain -n -2`; |
|
await execAsync(voiceCmd); |
|
|
|
|
|
const mixCommand = `sox -m voice_mod.wav noise.wav crackle.wav temp1.wav`; |
|
await execAsync(mixCommand); |
|
|
|
|
|
const effectCommand = `sox temp1.wav "${outputFile}" \ |
|
gain -n -2 \ |
|
sinc -n 4096 -b 48 300 \ |
|
sinc -n 4096 -b 48 -2700 \ |
|
compand 0.02,0.05 -6:-70,-60,-40,-30,-20 -8 -90 0.1 \ |
|
overdrive 25 \ |
|
treble -15 1.5k \ |
|
bass -12 400 \ |
|
echo 0.8 0.5 30 0.6 \ |
|
echo 0.6 0.3 15 0.4 \ |
|
tremolo 0.8 60 \ |
|
contrast 80`; |
|
await execAsync(effectCommand); |
|
|
|
|
|
await execAsync("rm noise.wav crackle.wav temp1.wav voice_mod.wav"); |
|
|
|
console.log("Effet radio ondes courtes (2K40J3E) appliqué avec succès!"); |
|
} catch (error) { |
|
console.error("Erreur lors de l'application de l'effet:", error); |
|
throw error; |
|
} |
|
} |
|
|
|
|
|
async function checkAndInstallSox(): Promise<void> { |
|
try { |
|
await execAsync("which sox"); |
|
console.log("Sox est déjà installé"); |
|
} catch { |
|
console.log("Installation de Sox..."); |
|
await execAsync( |
|
"sudo apt-get update && sudo apt-get install -y sox libsox-fmt-mp3" |
|
); |
|
console.log("Sox a été installé avec succès"); |
|
} |
|
} |
|
|
|
|
|
(async () => { |
|
try { |
|
await checkAndInstallSox(); |
|
await addMilitaryRadioEffect("output.mp3", "output-radio.mp3"); |
|
} catch (error) { |
|
console.error("Erreur:", error); |
|
} |
|
})(); |
|
|