Spaces:
Running
Running
Raivis Dejus
commited on
Commit
·
38cbd58
1
Parent(s):
bfaa16a
Adding app
Browse files- app.py +59 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio
|
2 |
+
import wave
|
3 |
+
import numpy as np
|
4 |
+
from io import BytesIO
|
5 |
+
from huggingface_hub import hf_hub_download
|
6 |
+
from piper import PiperVoice
|
7 |
+
|
8 |
+
|
9 |
+
def synthesize_speech(text, sentence_silence, length_scale):
|
10 |
+
model_path = hf_hub_download(repo_id="RaivisDejus/Piper-lv_LV-Aivars-medium", filename="Piper-lv_LV-Aivars-medium.onnx")
|
11 |
+
config_path = hf_hub_download(repo_id="RaivisDejus/Piper-lv_LV-Aivars-medium", filename="Piper-lv_LV-Aivars-medium.onnx.json")
|
12 |
+
|
13 |
+
voice = PiperVoice.load(model_path, config_path)
|
14 |
+
|
15 |
+
buffer = BytesIO()
|
16 |
+
with wave.open(buffer, 'wb') as wav_file:
|
17 |
+
wav_file.setframerate(voice.config.sample_rate)
|
18 |
+
wav_file.setsampwidth(2)
|
19 |
+
wav_file.setnchannels(1)
|
20 |
+
voice.synthesize(text, wav_file, sentence_silence=sentence_silence, length_scale=length_scale)
|
21 |
+
|
22 |
+
buffer.seek(0)
|
23 |
+
audio_data = np.frombuffer(buffer.read(), dtype=np.int16)
|
24 |
+
return audio_data.tobytes()
|
25 |
+
|
26 |
+
|
27 |
+
# Gradio Interface
|
28 |
+
with gradio.Blocks(theme=gradio.themes.Base()) as demo:
|
29 |
+
gradio.Markdown(
|
30 |
+
"""
|
31 |
+
# Latvian Piper TTS
|
32 |
+
|
33 |
+
Test Latvian Piper TTS [model](https://huggingface.co/RaivisDejus/Piper-lv_LV-Aivars-medium) Aivars.
|
34 |
+
|
35 |
+
Available parameters:
|
36 |
+
- Sentence silence - The `--sentence-silence` piper parameter controls silence duration between sentences.
|
37 |
+
- Length scale - The `--length-scale` piper parameter controls length and speach speed of generated audio.
|
38 |
+
|
39 |
+
Support development of Latvian speech technologies and contribute to the [Balsu talka](https://balsutalka.lv/).
|
40 |
+
""")
|
41 |
+
input_text = gradio.Textbox(
|
42 |
+
label="Text to generate",
|
43 |
+
lines=3,
|
44 |
+
value="“Balsu talka” ir projekts latviešu valodas nākotnei. Tā mērķis ir iemūžināt mūsdienās runāto latviešu valodu un nodrošināt latviešu valodas pieejamību tehnoloģiju attīstībai. Šo mērķi varam sasniegt tikai kopīgiem spēkiem, tāpēc aicinām katru ierunāt vismaz piecus teikumus, lai savāktu pēc iespējas vairāk runas paraugu un izveidotu daudzveidīgu, atvērtu un ikvienam pieejamu latviešu runas datu kopu."
|
45 |
+
)
|
46 |
+
sentence_silence = gradio.Slider(label="Sentence silence", minimum=0.0, maximum=2.0, step=0.05, value=0.2)
|
47 |
+
length_scale = gradio.Slider(label="Length scale", minimum=0.5, maximum=2.0, step=0.05, value=1.0)
|
48 |
+
submit_button = gradio.Button("Generate")
|
49 |
+
output_audio = gradio.Audio(
|
50 |
+
label="Generated speech",
|
51 |
+
autoplay=True,
|
52 |
+
type="numpy",
|
53 |
+
show_download_button=True,
|
54 |
+
show_share_button=False
|
55 |
+
)
|
56 |
+
|
57 |
+
submit_button.click(synthesize_speech, inputs=[input_text, sentence_silence, length_scale], outputs=[output_audio])
|
58 |
+
|
59 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
piper-tts
|