Spaces:
Runtime error
Runtime error
File size: 1,423 Bytes
3b211d2 b49bd76 dcb13fb 3b211d2 b6eacae 3b211d2 b6eacae b49bd76 dcb13fb b6eacae dcb13fb b6eacae b49bd76 3b211d2 b6eacae 3b211d2 b6eacae dcb13fb b6eacae dcb13fb 3b211d2 b49bd76 | 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 | import gradio as gr
from kokoro_onnx import Kokoro
import soundfile as sf
from huggingface_hub import hf_hub_download
import os
# Download seguro - Apontando para o repositório estável
print("Baixando modelos...")
try:
# Usando o repositório que contém os arquivos ONNX confirmados
model_path = hf_hub_download(repo_id="v006/kokoro", filename="kokoro-v0_19.onnx")
voices_path = hf_hub_download(repo_id="v006/kokoro", filename="voices.bin")
except Exception:
# Fallback para o repositório principal caso o acima falhe
model_path = hf_hub_download(repo_id="hexgrad/Kokoro-82M", filename="kokoro-v0_19.onnx")
voices_path = hf_hub_download(repo_id="hexgrad/Kokoro-82M", filename="voices.bin")
# Inicializa o motor TTS
model = Kokoro(model_path, voices_path)
def narrar(data):
texto = data.get("texto", "")
if not texto:
return None
# 'am_michael' é a voz masculina ideal: profunda, clara e solene
# speed=0.9 para dar o ritmo de leitura bíblica
samples, sample_rate = model.create(texto, voice="am_michael", speed=0.9)
output_file = "audio.wav"
sf.write(output_file, samples, sample_rate)
return output_file
# Interface Gradio configurada como API JSON
demo = gr.Interface(
fn=narrar,
inputs=gr.JSON(label="Input JSON"),
outputs=gr.Audio(label="Narração"),
api_name="predict"
)
if __name__ == "__main__":
demo.launch()
|