t / main.py
defkzn's picture
initial version
a841504
raw
history blame
743 Bytes
import tempfile
import gradio as gr
from piper import PiperVoice
from pathlib import Path
import wave
_FILE = Path(__file__)
_DIR = _FILE.parent
voice = PiperVoice.load(
model_path= _DIR / 'models/ro/ro_RO-mihai-medium.onnx',
config_path= _DIR / 'models/ro/ro_RO-mihai-medium.onnx.json'
)
synthesize_args = {}
def tts(text: str):
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
with wave.Wave_write(fp) as wav:
voice.synthesize(text, wav, **synthesize_args)
return fp.name
inputs = [gr.Textbox(label="Input", value="Salut, numele meu este Bogdan.", max_lines=10)]
outputs = gr.Audio(label="Output")
demo = gr.Interface(fn=tts, inputs=inputs, outputs=outputs)
demo.launch()