Mohamed Aymane Farhi commited on
Commit
3ab0a08
1 Parent(s): c4ca71a

Add other variants.

Browse files
Files changed (1) hide show
  1. app.py +27 -31
app.py CHANGED
@@ -2,36 +2,32 @@
2
  from ttsmms import TTS
3
  import gradio as gr
4
 
5
- tts = TTS("shi")
6
-
7
- def generate_voice(text):
8
- audio = tts.synthesis(text)
 
 
 
 
9
  return (audio['sampling_rate'], audio['x'])
10
 
11
- with gr.Blocks(title="Tachelhit Text to Speech with MMS") as blocks:
12
-
13
- gr.Markdown('# Tachelhit Text to Speech - MMS')
14
- gr.Markdown('MMS: Scaling Speech Technology to 1000+ languages by Meta AI')
15
-
16
- input_text = gr.Textbox(label="Input Text", lines=3)
17
- examples = gr.Examples(examples=["ġ-iḍ-an ġ-ilul-umsiggel, illas lḥal s-umdlu isemmiḍn.", "wala manis a-ttidun?"], inputs=[input_text])
18
-
19
- run_button = gr.Button(value="Run")
20
-
21
- out_audio = gr.Audio(
22
- label="Output Audio",
23
- type="numpy",
24
- )
25
-
26
- inputs = [input_text]
27
- outputs = [out_audio]
28
-
29
- run_button.click(
30
- fn=generate_voice,
31
- inputs=inputs,
32
- outputs=outputs,
33
- queue=True,
34
- )
35
-
36
-
37
- blocks.queue(concurrency_count=1).launch(debug=True)
 
2
  from ttsmms import TTS
3
  import gradio as gr
4
 
5
+ VARIANTS = ['shi', 'rif-script_latin', 'rif-script_arabic', 'kab', 'taq', 'ttq-script_tifinagh']
6
+ MODELS = {}
7
+
8
+ def tts(text, variant):
9
+ if variant not in MODELS:
10
+ MODELS[variant] = TTS(variant)
11
+ model = MODELS[variant]
12
+ audio = model.synthesis(text)
13
  return (audio['sampling_rate'], audio['x'])
14
 
15
+ examples = [["wala manis a-ttidun?", "shi"],
16
+ ["ġ-iḍ-an ġ-ilul-umsiggel, illas lḥal s-umdlu isemmiḍn.", "shi"]]
17
+
18
+ iface = gr.Interface(
19
+ fn=tts,
20
+ inputs=[
21
+ gr.inputs.Textbox(
22
+ label="Text",
23
+ default="Text to synthesize.",
24
+ ),
25
+ gr.inputs.Dropdown(label="Select a variant", choices=VARIANTS, default=VARIANTS[0])
26
+ ],
27
+ outputs=gr.outputs.Audio(label="Output", type="numpy"),
28
+ examples=examples,
29
+ title="🗣️ Tamazight Text to Speech with MMS 🗣️",
30
+ allow_flagging="manual",
31
+ flagging_options=['error', 'bad-quality', 'wrong-pronounciation'],
32
+ )
33
+ iface.launch()