Spaces:
Runtime error
Runtime error
File size: 1,382 Bytes
3b211d2 dcb13fb 3b211d2 dcb13fb 3b211d2 dcb13fb 3b211d2 dcb13fb 3b211d2 dcb13fb 3b211d2 dcb13fb 3b211d2 dcb13fb | 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 43 44 45 46 47 48 | import gradio as gr
from kokoro_onnx import Kokoro
import soundfile as sf
import os
import requests
# URLs dos arquivos oficiais (Kokoro 82M - O melhor para CPU em 2026)
MODEL_URL = "https://huggingface.co"
VOICES_URL = "https://huggingface.co"
def download_file(url, filename):
if not os.path.exists(filename):
print(f"Baixando {filename}...")
response = requests.get(url)
with open(filename, "wb") as f:
f.write(response.content)
print(f"{filename} baixado com sucesso.")
# Baixa os arquivos necessários para a memória do Space
download_file(MODEL_URL, "kokoro-v0_19.onnx")
download_file(VOICES_URL, "voices.bin")
# Inicializa o modelo
model = Kokoro("kokoro-v0_19.onnx", "voices.bin")
def narrar_biblia(data):
# O JSON deve vir no formato {"texto": "Sua historia aqui"}
texto = data.get("texto", "")
if not texto:
return None
# 'am_michael' é a voz masculina ideal (estilo narração épica/bíblica)
samples, sample_rate = model.create(texto, voice="am_michael", speed=1.0)
output_path = "narracao.wav"
sf.write(output_path, samples, sample_rate)
return output_path
# Interface configurada como API JSON
demo = gr.Interface(
fn=narrar_biblia,
inputs=gr.JSON(label="Input JSON"),
outputs=gr.Audio(label="Audio Gerado"),
api_name="predict"
)
demo.launch()
|