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