const axios = require("axios"); const fs = require("fs-extra"); const path = require("path"); const models = { "1": { name: "Joey", desc: "šŸ§‘ Male voice (American English)" }, "2": { name: "Amy", desc: "šŸ‘© Female voice (British English)" }, "3": { name: "Brian", desc: "šŸ§”ā€ā™‚ļø Male voice (British English)" }, "4": { name: "Mizuki", desc: "šŸ‘§ Female voice (Japanese)" } }; module.exports = { config: { name: "speak", version: "1.0", author: "Chitron Bhattacharjee", countDown: 5, role: 0, shortDescription: { en: "Text-to-speech using voice models" }, longDescription: { en: "Generate speech from text using selected voice models (no API key needed)" }, category: "media", guide: { en: `+speak Hello world +speak Hello there -m2 +speak -m (list voice models)` } }, onStart: async function ({ message, args, event }) { const input = args.join(" "); if (!input) return message.reply("ā— Please provide text. Example: `+speak Hello world`"); if (input.toLowerCase() === "-m") { const listMsg = ` šŸŽ¤ š—”š˜ƒš—®š—¶š—¹š—®š—Æš—¹š—² š—§š—§š—¦ š— š—¼š—±š—²š—¹š˜€: šŸ”¢ -m1: Joey šŸ§‘ Male voice (American English) šŸ”¢ -m2: Amy šŸ‘© Female voice (British English) šŸ”¢ -m3: Brian šŸ§”ā€ā™‚ļø Male voice (British English) šŸ”¢ -m4: Mizuki šŸ‘§ Female voice (Japanese) šŸ“ Use like: +speak Hello there -m2 `.trim(); return message.reply(listMsg); } // Extract model const modelMatch = input.match(/-m(\d+)/); const modelNum = modelMatch ? modelMatch[1] : "1"; const voice = models[modelNum]?.name; if (!voice) return message.reply("āŒ Invalid model number. Use `+speak -m` to see list."); // Remove -m flag from message const content = input.replace(`-m${modelNum}`, "").trim(); if (!content) return message.reply("ā— Text is empty after removing model flag."); try { const res = await axios.post("https://ttsmp3.com/makemp3_new.php", new URLSearchParams({ msg: content, lang: voice, source: "ttsmp3" }).toString(), { headers: { "Content-Type": "application/x-www-form-urlencoded" } }); if (!res.data || !res.data.URL) return message.reply("āš ļø Failed to generate audio."); const fileName = `tts_${Date.now()}.mp3`; const filePath = path.join(__dirname, "cache", fileName); const audioRes = await axios.get(res.data.URL, { responseType: "stream" }); await fs.ensureDir(path.dirname(filePath)); const writer = fs.createWriteStream(filePath); audioRes.data.pipe(writer); writer.on("finish", () => { message.reply({ body: `šŸ—£ļø *${content}*\nšŸŽ¤ Voice: ${voice}`, attachment: fs.createReadStream(filePath) }); }); } catch (err) { console.error(err); return message.reply("āŒ Error occurred while generating speech."); } } };