File size: 2,250 Bytes
b740fff
 
 
 
828732e
 
 
 
 
 
 
af86d6e
 
b35a9f7
af86d6e
b35a9f7
 
 
 
 
 
 
 
 
 
 
af86d6e
 
3ab0a08
 
 
ec56fd8
 
 
 
b35a9f7
 
 
 
3ab0a08
b740fff
 
c8442dd
 
af86d6e
 
5b9aa0e
 
3ab0a08
9da07f8
 
3ab0a08
 
 
b35a9f7
3ab0a08
77de335
3ab0a08
77de335
 
 
 
 
3ab0a08
b35a9f7
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*- 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'
             }

mapping = {'ɣ': 'ġ',
           'v': 'ġ',
           'c': 'š',
           'x': 'ḫ',
           'T': 'ṭ',
           'S': 'ṣ',
           'D': 'ḍ',
           'H': 'ḥ',
           'Z': 'ẓ',
           '3': 'ε',
           '7': 'ḥ',
           '9': 'q',
           'gh': 'ġ',
           'kh': 'ḫ'
          }

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]

    if variant_code == 'shi':
        for key, value in mapping.items():
            text = text.replace(key, value)
    audio = model.synthesis(text)
    return (audio['sampling_rate'], audio['x'])

examples = [["Riɣ ad cceɣ s ufus kḍuɣ s inxar", "Tachelhit"],
            ["arraw n lhem yukr aɣ ihdumn nɣ", "Tachelhit"],
            ["wa tamɣart ma d ukan teskart ?", "Tachelhit"],
            ["ar d iṭṭar unẓar, ffuɣn d igḍaḍ, mmɣin d ijjign", "Tachelhit"],
            ["Egg lxir di timura, ad tafed di tiwwura.", "Tarifit (Latin script)"],
            ["Aqemmum iqnen ur ṯ-ttidfen izan.", "Tarifit (Latin script)"]]

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

iface = gr.Interface(
    fn=tts,
    inputs=[
        gr.Textbox(
            label="Text",
            value="Text to synthesize."
        ),
        gr.Dropdown(
            label="Variant",
            choices=list(ISO_CODES.keys()),
            value="Tachelhit"
        )
    ],
    outputs=gr.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()