Spaces:
Runtime error
Runtime error
| 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() | |