Spaces:
Running
Running
import gradio as gr | |
import subprocess | |
import os | |
import uuid | |
MODEL = "en_US-amy-medium.onnx" | |
MODEL_PATH = f"./models/en_US/{MODEL}" | |
CONFIG_PATH = f"./models/en_US/en_US-amy-medium.onnx.json" | |
# Download model from Hugging Face if not present | |
if not os.path.exists(MODEL_PATH): | |
os.makedirs("./models/en_US", exist_ok=True) | |
subprocess.run(["wget", "-O", MODEL_PATH, | |
"https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_US/amy-medium.onnx"]) | |
subprocess.run(["wget", "-O", CONFIG_PATH, | |
"https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_US/en_US-amy-medium.onnx.json"]) | |
def tts_piper(text): | |
output_file = f"output_{uuid.uuid4().hex}.wav" | |
command = [ | |
"piper", | |
"--model", MODEL_PATH, | |
"--config", CONFIG_PATH, | |
"--output_file", output_file, | |
"--text", text | |
] | |
subprocess.run(command) | |
return output_file | |
demo = gr.Interface(fn=tts_piper, inputs="text", outputs="audio", title="Piper TTS - Hugging Face Demo") | |
demo.launch() | |