Spaces:
Sleeping
Sleeping
File size: 2,023 Bytes
8d8b0ad |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
const axios = require('axios');
const config = require('../config')
const {cmd , commands} = require('../command')
const googleTTS = require('google-tts-api')
cmd({
pattern: "trt",
alias: ["translate"],
desc: "🌍 Translate text between languages",
react: "⚡",
category: "other",
filename: __filename
},
async (conn, mek, m, { from, q, reply }) => {
try {
const args = q.split(' ');
if (args.length < 2) return reply("❗ Please provide a language code and text. Usage: .translate [language code] [text]");
const targetLang = args[0];
const textToTranslate = args.slice(1).join(' ');
const url = `https://api.mymemory.translated.net/get?q=${encodeURIComponent(textToTranslate)}&langpair=en|${targetLang}`;
const response = await axios.get(url);
const translation = response.data.responseData.translatedText;
const translationMessage = `> *SUBZERO MD TRANSLATION*
> 🔤 *Original*: ${textToTranslate}
> 🔠 *Translated*: ${translation}
> 🌐 *Language*: ${targetLang.toUpperCase()}`;
return reply(translationMessage);
} catch (e) {
console.log(e);
return reply("⚠️ An error occurred data while translating the your text. Please try again later🤕");
}
});
//____________________________TTS___________________________
cmd({
pattern: "tts",
desc: "download songs",
category: "download",
react: "👧",
filename: __filename
},
async(conn, mek, m,{from, quoted, body, isCmd, command, args, q, isGroup, sender, senderNumber, botNumber2, botNumber, pushname, isMe, isOwner, groupMetadata, groupName, participants, groupAdmins, isBotAdmins, isAdmins, reply}) => {
try{
if(!q) return reply("Need some text.")
const url = googleTTS.getAudioUrl(q, {
lang: 'hi-IN',
slow: false,
host: 'https://translate.google.com',
})
await conn.sendMessage(from, { audio: { url: url }, mimetype: 'audio/mpeg', ptt: true }, { quoted: mek })
}catch(a){
reply(`${a}`)
}
})
|