(sock, chatId, text, message, language = 'en')
| 3 | const path = require('path'); |
| 4 | |
| 5 | async function ttsCommand(sock, chatId, text, message, language = 'en') { |
| 6 | if (!text) { |
| 7 | await sock.sendMessage(chatId, { text: 'Please provide the text for TTS conversion.' }); |
| 8 | return; |
| 9 | } |
| 10 | |
| 11 | const fileName = `tts-${Date.now()}.mp3`; |
| 12 | const filePath = path.join(__dirname, '..', 'assets', fileName); |
| 13 | |
| 14 | const gtts = new gTTS(text, language); |
| 15 | gtts.save(filePath, async function (err) { |
| 16 | if (err) { |
| 17 | await sock.sendMessage(chatId, { text: 'Error generating TTS audio.' }); |
| 18 | return; |
| 19 | } |
| 20 | |
| 21 | await sock.sendMessage(chatId, { |
| 22 | audio: { url: filePath }, |
| 23 | mimetype: 'audio/mpeg' |
| 24 | }, { quoted: message }); |
| 25 | |
| 26 | fs.unlinkSync(filePath); |
| 27 | }); |
| 28 | } |
| 29 | |
| 30 | module.exports = ttsCommand; |
nothing calls this directly
no outgoing calls
no test coverage detected