Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,33 +4,38 @@ import soundfile as sf
|
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
import os
|
| 6 |
|
| 7 |
-
# Download
|
| 8 |
-
print("Baixando
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
# Inicializa o
|
| 13 |
model = Kokoro(model_path, voices_path)
|
| 14 |
|
| 15 |
-
def
|
| 16 |
-
|
| 17 |
-
texto = json_input.get("texto", "")
|
| 18 |
if not texto:
|
| 19 |
return None
|
| 20 |
|
| 21 |
-
# 'am_michael' é
|
| 22 |
-
# speed
|
| 23 |
samples, sample_rate = model.create(texto, voice="am_michael", speed=0.9)
|
| 24 |
|
| 25 |
-
|
| 26 |
-
sf.write(
|
| 27 |
-
return
|
| 28 |
|
| 29 |
-
#
|
| 30 |
demo = gr.Interface(
|
| 31 |
-
fn=
|
| 32 |
-
inputs=gr.JSON(label="
|
| 33 |
-
outputs=gr.Audio(label="
|
| 34 |
api_name="predict"
|
| 35 |
)
|
| 36 |
|
|
|
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
import os
|
| 6 |
|
| 7 |
+
# Download seguro - Apontando para o repositório estável
|
| 8 |
+
print("Baixando modelos...")
|
| 9 |
+
try:
|
| 10 |
+
# Usando o repositório que contém os arquivos ONNX confirmados
|
| 11 |
+
model_path = hf_hub_download(repo_id="v006/kokoro", filename="kokoro-v0_19.onnx")
|
| 12 |
+
voices_path = hf_hub_download(repo_id="v006/kokoro", filename="voices.bin")
|
| 13 |
+
except Exception:
|
| 14 |
+
# Fallback para o repositório principal caso o acima falhe
|
| 15 |
+
model_path = hf_hub_download(repo_id="hexgrad/Kokoro-82M", filename="kokoro-v0_19.onnx")
|
| 16 |
+
voices_path = hf_hub_download(repo_id="hexgrad/Kokoro-82M", filename="voices.bin")
|
| 17 |
|
| 18 |
+
# Inicializa o motor TTS
|
| 19 |
model = Kokoro(model_path, voices_path)
|
| 20 |
|
| 21 |
+
def narrar(data):
|
| 22 |
+
texto = data.get("texto", "")
|
|
|
|
| 23 |
if not texto:
|
| 24 |
return None
|
| 25 |
|
| 26 |
+
# 'am_michael' é a voz masculina ideal: profunda, clara e solene
|
| 27 |
+
# speed=0.9 para dar o ritmo de leitura bíblica
|
| 28 |
samples, sample_rate = model.create(texto, voice="am_michael", speed=0.9)
|
| 29 |
|
| 30 |
+
output_file = "audio.wav"
|
| 31 |
+
sf.write(output_file, samples, sample_rate)
|
| 32 |
+
return output_file
|
| 33 |
|
| 34 |
+
# Interface Gradio configurada como API JSON
|
| 35 |
demo = gr.Interface(
|
| 36 |
+
fn=narrar,
|
| 37 |
+
inputs=gr.JSON(label="Input JSON"),
|
| 38 |
+
outputs=gr.Audio(label="Narração"),
|
| 39 |
api_name="predict"
|
| 40 |
)
|
| 41 |
|