Spaces:
Running
Running
# -*- 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 = {'ɣ': 'ġ', | |
'c': 'š', | |
'x': 'ḫ' | |
} | |
MODELS = {} | |
def tts(text, variant): | |
text = text.lower() | |
variant_code = ISO_CODES[variant] | |
if variant_code == 'shi': | |
for key, value in mapping.items(): | |
text = text.replace(key, value) | |
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 = [["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.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() |