File size: 1,517 Bytes
b740fff
 
 
 
828732e
 
 
 
 
 
 
 
3ab0a08
 
 
ec56fd8
 
 
 
3ab0a08
b740fff
 
44243d4
 
3ab0a08
9da07f8
 
3ab0a08
 
 
 
 
 
 
ec56fd8
3ab0a08
 
 
9da07f8
 
3ab0a08
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
from ttsmms import TTS
import gradio as gr

ISO_CODES = {'Tachelhit': 'shi',
             'Tarifit (Latin script)': 'rif-script_latin',
             'Tarifit (Arabic script)': 'rif-script_arabic',
             'Taqbaylit': 'kab',
             'Tamasheq': 'taq',
             'Tamajaq, Tawallammat (Tifinagh script)': 'ttq-script_tifinagh'
             }
VARIANTS = list(ISO_CODES.values())
MODELS = {}

def tts(text, variant):
    variant_code = ISO_CODES[variant]
    if variant_code not in MODELS:
        MODELS[variant_code] = TTS(variant_code)
    model = MODELS[variant_code]
    audio = model.synthesis(text)
    return (audio['sampling_rate'], audio['x'])

examples = [["wala manis a-ttidun?", "Tachelhit"],
            ["ġ-iḍ-an ġ-ilul-umsiggel, illas lḥal s-umdlu isemmiḍn.", "Tachelhit"]]

description = "Text-to-speech for Tachelhit, Tarifit, Taqbaylit, Tamasheq and Tamajaq (Tawallammat)."

iface = gr.Interface(
    fn=tts,
    inputs=[
        gr.inputs.Textbox(
            label="Text",
            default="Text to synthesize.",
        ),
        gr.inputs.Dropdown(label="Variant", choices=list(ISO_CODES.keys()), default="Tachelhit")
    ],
    outputs=gr.outputs.Audio(label="Output", type="numpy"),
    examples=examples,
    title="🗣️ Tamazight Text-to-Speech with MMS (Massively Multilingual Speech) 🗣️",
    description=description,
    allow_flagging="manual",
    flagging_options=['error', 'bad-quality', 'wrong-pronounciation'],
)
iface.launch()