import { exec } from "child_process"; import { promisify } from "util"; const execAsync = promisify(exec); async function addMilitaryRadioEffect( inputFile: string, outputFile: string ): Promise { try { // Obtenir le taux d'échantillonnage du fichier d'entrée const { stdout: sampleRate } = await execAsync(`soxi -r "${inputFile}"`); const rate = sampleRate.trim(); // Création du bruit blanc temporaire avec le même taux d'échantillonnage const noiseCmd = `sox -r ${rate} -n noise.wav synth 10 whitenoise vol 0.15`; await execAsync(noiseCmd); // Création des grésillements temporaires (bande typique ondes courtes) const crackleCmd = `sox -r ${rate} -n crackle.wav synth 10 whitenoise band -n 300 2700 vol 0.1`; await execAsync(crackleCmd); // Traitement initial de la voix avec filtres ondes courtes (2K40J3E) 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); // Mélange des effets const mixCommand = `sox -m voice_mod.wav noise.wav crackle.wav temp1.wav`; await execAsync(mixCommand); // Application des effets finaux 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); // Nettoyage des fichiers temporaires 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; } } // Installation de sox si nécessaire async function checkAndInstallSox(): Promise { 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"); } } // Utilisation (async () => { try { await checkAndInstallSox(); await addMilitaryRadioEffect("output.mp3", "output-radio.mp3"); } catch (error) { console.error("Erreur:", error); } })();