|
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/rmedium.onnx', |
|
config_path=_DIR / 'models/rmedium.onnx.json' |
|
) |
|
synthesize_args = {} |
|
|
|
|
|
def tts(text: str): |
|
print(text) |
|
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() |
|
|