Spaces:
No application file
No application file
File size: 1,182 Bytes
21b9e96 23f321d 21b9e96 23f321d 21b9e96 23f321d |
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 streamlit as st
import requests
import base64
import os
from dotenv import load_dotenv
# Cargar variables del .env
load_dotenv()
API_URL = "https://api-inference.huggingface.co/models/espnet/kan-bayashi_ljspeech_vits"
HF_TOKEN = os.getenv("TOKEN") # ← OBTENIDO DESDE .env
if HF_TOKEN is None:
st.error("❌ ERROR: No se encontró la variable TOKEN en el .env")
st.stop()
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
def text_to_speech(text):
payload = {"inputs": text}
response = requests.post(API_URL, headers=headers, json=payload)
return response.content
st.title("Texto a Voz Accesible")
st.write("Aplicación para personas con discapacidades visuales o cognitivas.")
texto = st.text_area("Escribe el texto que quieres convertir a audio")
if st.button("Generar Audio"):
if texto.strip() == "":
st.warning("Introduce texto para convertir.")
else:
audio_bytes = text_to_speech(texto)
st.audio(audio_bytes, format="audio/wav")
st.download_button(
label="Descargar audio",
data=audio_bytes,
file_name="voz_generada.wav",
mime="audio/wav",
) |