Spaces:
Running on Zero
Running on Zero
Upload 2 files
Browse files- app.py +79 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import tempfile
|
| 4 |
+
from importlib.resources import files
|
| 5 |
+
from silma_tts.api import SilmaTTS
|
| 6 |
+
|
| 7 |
+
print("Loading SILMA TTS model...", flush=True)
|
| 8 |
+
silma_tts = SilmaTTS()
|
| 9 |
+
|
| 10 |
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 11 |
+
ref_audio_dir = os.path.join(current_dir, "infer", "ref_audio_samples")
|
| 12 |
+
|
| 13 |
+
def do_inference(ref_audio, ref_text, gen_text):
|
| 14 |
+
if not ref_audio:
|
| 15 |
+
return None
|
| 16 |
+
|
| 17 |
+
_, output_wav_path = tempfile.mkstemp(suffix=".wav")
|
| 18 |
+
|
| 19 |
+
wav, sr, _ = silma_tts.infer(
|
| 20 |
+
ref_file=ref_audio,
|
| 21 |
+
ref_text=ref_text,
|
| 22 |
+
gen_text=gen_text,
|
| 23 |
+
file_wave=output_wav_path,
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
return output_wav_path
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
with gr.Blocks() as demo:
|
| 30 |
+
gr.Markdown("# SILMA TTS Demo")
|
| 31 |
+
gr.Markdown("Add reference audio, reference text and generation text then click 'Generate Speech'")
|
| 32 |
+
|
| 33 |
+
with gr.Row():
|
| 34 |
+
with gr.Column():
|
| 35 |
+
# Define inputs
|
| 36 |
+
ref_audio_input = gr.Audio(
|
| 37 |
+
label="Reference Audio",
|
| 38 |
+
type="filepath",
|
| 39 |
+
value=ref_audio_dir+"/ar.ref.24k.wav"
|
| 40 |
+
)
|
| 41 |
+
ref_text_input = gr.Textbox(
|
| 42 |
+
label="Reference Text",
|
| 43 |
+
value="ويدقق النظر في القرآن الكريم وسائر الكتب السماوية ويتبع مسالك الرسل العظام عليهم الصلاة والسلام."
|
| 44 |
+
)
|
| 45 |
+
gen_text_input = gr.Textbox(
|
| 46 |
+
label="Generation Text",
|
| 47 |
+
lines=5,
|
| 48 |
+
value="""
|
| 49 |
+
أنا نموذج جديد من سلمى لتحويل النص إلى كلام، يمكنني التحدث باللغة العربية مع أو بدون علامات التشكيل.
|
| 50 |
+
I am the new SILMA model for converting text to speech, I can speak Arabic with or without diacritics.
|
| 51 |
+
""".strip()
|
| 52 |
+
)
|
| 53 |
+
submit_btn = gr.Button("Generate Speech")
|
| 54 |
+
|
| 55 |
+
with gr.Column():
|
| 56 |
+
audio_output = gr.Audio(label="Generated Speech")
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
# When ref_audio_input changes, we update ref_text_input with an empty string
|
| 60 |
+
ref_audio_input.input(
|
| 61 |
+
fn=lambda: "",
|
| 62 |
+
inputs=None,
|
| 63 |
+
outputs=ref_text_input
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
# Set up the click event for the button
|
| 67 |
+
submit_btn.click(
|
| 68 |
+
fn=do_inference,
|
| 69 |
+
inputs=[ref_audio_input, ref_text_input, gen_text_input],
|
| 70 |
+
outputs=audio_output
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
def main():
|
| 74 |
+
print("Starting app...")
|
| 75 |
+
|
| 76 |
+
demo.queue().launch(server_name="0.0.0.0", server_port=7860, allowed_paths=[ref_audio_dir])
|
| 77 |
+
|
| 78 |
+
if __name__ == "__main__":
|
| 79 |
+
main()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
silma-tts
|
| 2 |
+
gradio
|