forked from xIKRATOSx/Shizu-Bot-MD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvertidor-tts.js
42 lines (38 loc) Β· 1.3 KB
/
convertidor-tts.js
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
import gtts from 'node-gtts'
import { readFileSync, unlinkSync } from 'fs'
import { join } from 'path'
const defaultLang = 'es'
let handler = async (m, { conn, args, usedPrefix, command }) => {
let lang = args[0]
let text = args.slice(1).join(' ')
if ((args[0] || '').length !== 2) {
lang = defaultLang
text = args.join(' ')
}
if (!text && m.quoted?.text) text = m.quoted.text
let res
try { res = await tts(text, lang) }
catch (e) {
m.reply(e + '')
text = args.join(' ')
if (!text) throw `*[βπππ
πβ] πΈπ½ππ΄πππ΄ π΄π» ππ΄πππΎ πππ΄ πππΈπ΄ππ° π²πΎπ½π
π΄πππΈπ π° π½πΎππ° π³π΄ π
πΎπ, π΄πΉπ΄πΌπΏπ»πΎ: ${usedPrefix + command} es Hola Mundo*`
res = await tts(text, defaultLang)
} finally {
if (res) conn.sendFile(m.chat, res, 'tts.opus', null, m, true)
}}
handler.help = ['tts <lang> <teks>']
handler.tags = ['tools']
handler.command = /^g?tts$/i
export default handler
function tts(text, lang = 'es') {
console.log(lang, text)
return new Promise((resolve, reject) => {
try {
let tts = gtts(lang)
let filePath = join(global.__dirname(import.meta.url), '../tmp', (1 * new Date) + '.wav')
tts.save(filePath, text, () => {
resolve(readFileSync(filePath))
unlinkSync(filePath)
})
} catch (e) { reject(e) }
})}