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