Spaces:
Running
Running
clonar voz
Browse files- __pycache__/utils.cpython-39.pyc +0 -0
- app.py +54 -0
- requirements.txt +5 -0
- utils.py +32 -0
__pycache__/utils.cpython-39.pyc
ADDED
|
Binary file (1.46 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
|
| 3 |
+
import streamlit as st
|
| 4 |
+
import tempfile
|
| 5 |
+
from utils import VoiceCloner
|
| 6 |
+
|
| 7 |
+
def main():
|
| 8 |
+
st.title("Clonaci贸n de Voz en Espa帽ol")
|
| 9 |
+
st.write("""
|
| 10 |
+
Esta aplicaci贸n de ejemplo utiliza **Coqui TTS** (YourTTS) para
|
| 11 |
+
realizar clonaci贸n de voz en espa帽ol mediante zero-shot.
|
| 12 |
+
""")
|
| 13 |
+
|
| 14 |
+
# Creamos una instancia del clonador de voz
|
| 15 |
+
voice_cloner = VoiceCloner()
|
| 16 |
+
|
| 17 |
+
# Entrada de texto
|
| 18 |
+
text_input = st.text_area("Ingresa el texto a reproducir:", "")
|
| 19 |
+
|
| 20 |
+
# Carga de archivo de audio (WAV o MP3)
|
| 21 |
+
uploaded_audio = st.file_uploader("Sube una nota de voz o audio de referencia", type=["wav", "mp3"])
|
| 22 |
+
|
| 23 |
+
# Bot贸n para generar la voz clonada
|
| 24 |
+
if st.button("Generar voz clonada"):
|
| 25 |
+
# Validaciones b谩sicas
|
| 26 |
+
if not text_input:
|
| 27 |
+
st.warning("Por favor, ingresa un texto.")
|
| 28 |
+
elif not uploaded_audio:
|
| 29 |
+
st.warning("Por favor, sube un archivo de audio de referencia.")
|
| 30 |
+
else:
|
| 31 |
+
# Guardamos temporalmente el audio subido
|
| 32 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
|
| 33 |
+
tmp.write(uploaded_audio.read())
|
| 34 |
+
reference_audio_path = tmp.name
|
| 35 |
+
|
| 36 |
+
# Definimos un archivo de salida
|
| 37 |
+
output_path = "cloned_voice.wav"
|
| 38 |
+
|
| 39 |
+
# Llamamos a la funci贸n que clona la voz
|
| 40 |
+
result_audio_path = voice_cloner.clone_voice(
|
| 41 |
+
text=text_input,
|
| 42 |
+
reference_audio_path=reference_audio_path,
|
| 43 |
+
output_path=output_path
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
st.success("隆Voz clonada generada con 茅xito!")
|
| 47 |
+
|
| 48 |
+
# Leemos el audio generado y lo reproducimos
|
| 49 |
+
with open(result_audio_path, "rb") as audio_file:
|
| 50 |
+
audio_bytes = audio_file.read()
|
| 51 |
+
st.audio(audio_bytes, format="audio/wav")
|
| 52 |
+
|
| 53 |
+
if __name__ == "__main__":
|
| 54 |
+
main()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
TTS
|
| 3 |
+
torch
|
| 4 |
+
torchaudio
|
| 5 |
+
numpy
|
utils.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# utils.py
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
from TTS.api import TTS
|
| 5 |
+
|
| 6 |
+
class VoiceCloner:
|
| 7 |
+
def __init__(self, model_name: str = "tts_models/multilingual/multi-dataset/your_tts"):
|
| 8 |
+
"""
|
| 9 |
+
Inicializa el clonador de voz cargando el modelo de TTS.
|
| 10 |
+
:param model_name: Nombre del modelo preentrenado para TTS.
|
| 11 |
+
"""
|
| 12 |
+
self.model_name = model_name
|
| 13 |
+
self.model = TTS(model_name)
|
| 14 |
+
|
| 15 |
+
def clone_voice(self, text: str, reference_audio_path: str, output_path: str = "output.wav") -> str:
|
| 16 |
+
"""
|
| 17 |
+
Genera un archivo de audio con la voz clonada a partir de un audio de referencia.
|
| 18 |
+
|
| 19 |
+
:param text: El texto que se desea sintetizar.
|
| 20 |
+
:param reference_audio_path: Path del archivo de audio que servir谩 como referencia de voz.
|
| 21 |
+
:param output_path: Path de salida para el archivo de audio resultante.
|
| 22 |
+
:return: Path del archivo de audio generado.
|
| 23 |
+
"""
|
| 24 |
+
# 'YourTTS' permite zero-shot voice cloning siempre que se provea speaker_wav con el audio de referencia
|
| 25 |
+
# Si quieres forzar el idioma a espa帽ol, puedes usar el par谩metro language="es"
|
| 26 |
+
self.model.tts_to_file(
|
| 27 |
+
text=text,
|
| 28 |
+
speaker_wav=reference_audio_path,
|
| 29 |
+
language="es",
|
| 30 |
+
file_path=output_path
|
| 31 |
+
)
|
| 32 |
+
return output_path
|