import gradio as gr import os from AinaTheme import theme import phonemizer from dotenv import load_dotenv import logging load_dotenv() MAX_INPUT_TEXT_LEN = int(os.environ.get("MAX_INPUT_TEXT_LEN", default=325)) critical_logger = logging.getLogger("phonemizer") critical_logger.setLevel(logging.CRITICAL) # init phonemizers global_phonemizer_central = phonemizer.backend.EspeakBackend( language="ca", preserve_punctuation=True, with_stress=True, language_switch="remove-flags", logger=critical_logger, ) global_phonemizer_valencia = phonemizer.backend.EspeakBackend( language="ca-va", preserve_punctuation=True, with_stress=True, language_switch="remove-flags", logger=critical_logger, ) global_phonemizer_occidental = phonemizer.backend.EspeakBackend( language="ca-nw", preserve_punctuation=True, with_stress=True, language_switch="remove-flags", logger=critical_logger, ) global_phonemizer_balear = phonemizer.backend.EspeakBackend( language="ca-ba", preserve_punctuation=True, with_stress=True, language_switch="remove-flags", logger=critical_logger, ) global_phonemizer_algueres = phonemizer.backend.EspeakBackend( language="ca-al", preserve_punctuation=True, with_stress=True, language_switch="remove-flags", logger=critical_logger, ) global_phonemizer_rossellones = phonemizer.backend.EspeakBackend( language="ca-ro", preserve_punctuation=True, with_stress=True, language_switch="remove-flags", logger=critical_logger, ) def phonemiser(text, dialect): phonemizers = {"Central": global_phonemizer_central, "Valencian": global_phonemizer_valencia, "North-West": global_phonemizer_occidental, "Balear": global_phonemizer_balear, "Alguerés": global_phonemizer_algueres, "Rosellonés": global_phonemizer_rossellones} fonemitzador = phonemizers[dialect] #Set correct dialect for the phonemiser # synthesize fonemes = fonemitzador.phonemize([text], strip=True, njobs=1)[0] return fonemes title = "Transcripció fonètica multidialectal en català️" description=""" Transcripció fonètica per a diferents dialectes del català mitjançant eSpeak. Phonetic transcription for different dialects of Catalan using eSpeak. repo: https://github.com/projecte-aina/espeak-ng/tree/dev-ca """ def submit_input(input_, dialect): output = None if input_ is not None and len(input_) < MAX_INPUT_TEXT_LEN: output = phonemiser(input_, dialect) else: gr.Warning(f"Your text exceeds the {MAX_INPUT_TEXT_LEN}-character limit.") return output def change_interactive(text): input_state = text if input_state.strip() != "": return gr.update(interactive = True) else: return gr.update(interactive = False) def clean(): return ( None, None, ) with gr.Blocks(theme=theme) as app: gr.Markdown(f"