-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0dd9199
commit 006e30c
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import fetch from 'node-fetch'; | ||
|
||
const handler = async (m, { conn, usedPrefix, command, text }) => { | ||
const match = text.match(/^(\w+)\s*\|\s*(.+)/i); | ||
if (!match) { | ||
const voices = await getVoices(); | ||
const voiceNames = voices.voices.map(voice => voice.name).join('\nβ '); | ||
return m.reply(`*[β] Formato de uso erroneo, voz o texto faltante.*\n\n*ββ Ejemplo:*\nβ ${usedPrefix + command} nombre_voz | texto\n\n*ββ Ejemplo de uso:*\nβ ${usedPrefix + command} ${voices.voices[0].name} | este es un texto de ejemplo\n\n*ββ Lista de voces disponibles:*\nβ ${voiceNames}` | ||
); | ||
} | ||
const [, voiceName, inputText] = match; | ||
const voices = await getVoices(); | ||
const voice = voices.voices.find(voice => voice.name.toLowerCase() === voiceName.toLowerCase()); | ||
if (!voice) { | ||
const voiceNames = voices.voices.map(voice => voice.name).join('\nβ '); | ||
return m.reply( | ||
`[β] No se encontrΓ³ ninguna voz con el nombre "${voiceName}".\n\nββ Lista de voces disponibles:\nβ ${voiceNames}` | ||
); | ||
} | ||
const audio = await convertTextToSpeech(inputText, voice.voice_id); | ||
if (audio) { | ||
conn.sendMessage(m.chat, { audio: audio.audio, fileName: `error.mp3`, mimetype: 'audio/mpeg', ptt: true }, { quoted: m }); | ||
} | ||
}; | ||
|
||
handler.command = /^(tts3)$/i; | ||
export default handler; | ||
|
||
const apiKey = 'a0e2c6022f1aeb28b5020b1dd0faf6ee'; | ||
const getVoices = async () => { | ||
const url = 'https://api.elevenlabs.io/v1/voices'; | ||
const options = { method: 'GET', headers: { 'Content-Type': 'application/json', 'xi-api-key': apiKey }}; | ||
try { | ||
const response = await fetch(url, options); | ||
const voices = await response.json(); | ||
return voices; | ||
} catch (error) { | ||
console.error('Error al obtener las voces:', error); | ||
return []; | ||
} | ||
}; | ||
|
||
const convertTextToSpeech = async (text, voiceId) => { | ||
const url = `https://api.elevenlabs.io/v1/text-to-speech/${voiceId}`; | ||
const options = { method: 'POST', headers: { 'Content-Type': 'application/json', 'xi-api-key': apiKey }, body: JSON.stringify({ text: text, model_id: 'eleven_monolingual_v1', voice_settings: { stability: 0.5, similarity_boost: 0.5 }})}; | ||
try { | ||
const response = await fetch(url, options); | ||
const audioBuffer = await response.buffer(); | ||
return { audio: audioBuffer }; | ||
} catch (error) { | ||
console.error('Error al generar el audio:', error); | ||
return []; | ||
} | ||
}; |