| 64 | description: 'Apply audio effects to voice notes', |
| 65 | usage: '.bass / .nightcore (reply to audio)', |
| 66 | async handler(sock, message, args, context) { |
| 67 | const chatId = context.chatId || message.key.remoteJid; |
| 68 | const cmd = message.body || args.join(' '); |
| 69 | const filter = getFilter(cmd); |
| 70 | const audioBuffer = await getAudio(message); |
| 71 | if (!audioBuffer || !filter) { |
| 72 | return await sock.sendMessage(chatId, { text: effectsMenu }, { quoted: message }); |
| 73 | } |
| 74 | try { |
| 75 | const tmp = path.join(process.cwd(), 'tmp'); |
| 76 | if (!fs.existsSync(tmp)) |
| 77 | fs.mkdirSync(tmp, { recursive: true }); |
| 78 | const input = path.join(tmp, `in_${Date.now()}.ogg`); |
| 79 | const output = path.join(tmp, `out_${Date.now()}.ogg`); |
| 80 | fs.writeFileSync(input, audioBuffer); |
| 81 | exec(`ffmpeg -y -i "${input}" -af "${filter},aresample=48000,asetpts=N/SR" -c:a libopus -b:a 64k -ac 1 "${output}"`, async () => { |
| 82 | const out = fs.readFileSync(output); |
| 83 | await sock.sendMessage(chatId, { audio: out, mimetype: 'audio/ogg; codecs=opus', ptt: true }, { quoted: message }); |
| 84 | try { |
| 85 | fs.unlinkSync(input); |
| 86 | } |
| 87 | catch { } |
| 88 | try { |
| 89 | fs.unlinkSync(output); |
| 90 | } |
| 91 | catch { } |
| 92 | }); |
| 93 | } |
| 94 | catch { |
| 95 | await sock.sendMessage(chatId, { text: '❌ Audio processing failed. Make sure ffmpeg is installed.' }, { quoted: message }); |
| 96 | } |
| 97 | } |
| 98 | }; |