import tempfile import gradio as gr import os from espeak_phonemizer import Phonemizer MAX_TXT_LEN = 325 #fonemitzador = Phonemizer("ca") request_count = 0 def phonemiser(text, dialect): dialects = {"Central": "ca", "Valencian": "ca-va", "North-West": "ca-nw"} dialect = dialects[dialect] #Define dialect from espeak-ng-data/lang/roa/ca* fonemitzador = Phonemizer(dialect) #Set correct dialect for the phonemiser if len(text) > MAX_TXT_LEN: text = text[:MAX_TXT_LEN] print(f"Input text was cutoff since it went over the {MAX_TXT_LEN} character limit.") print(text) # synthesize fonemes = fonemitzador.phonemize(text, keep_clause_breakers=True) global request_count request_count += 1 print(f"Requests: {request_count}") return fonemes description=""" Transcripció fonètica en català Transcipció fonètica per a diferents dialectes del català mitjançant eSpeak. Phonetic transcription for different dialects of Catalan using eSpeak. """ article= "" iface = gr.Interface( fn=phonemiser, inputs=[ gr.Textbox( label="Text", value="L'Èlia i l'Alí a l'aula. L'oli i l'ou. Lulú olorava la lila.", ), gr.Dropdown(label="Dialect", choices=["Central", "Valencian", "North-West"], value="Central", ) ], outputs=[ gr.Markdown(label="Fonemes") ], title="Comparativa de síntesi lliure en català️", description=description, article=article, allow_flagging="never", layout="vertical", live=False, examples=[ ["Duc pà sec al sac, m'assec on sóc i el suco amb suc", "ca", "ca"], ["Un plat pla blanc, ple de pebre negre n’era. Un plat blanc pla, ple de pebre negre està", "ca-va", "ca-va"], ["Visc al bosc i busco vesc i visc del vesc que busco al bosc", "ca-nw", "ca-nw"], ["Una polla xica, pica, pellarica, camatorta i becarica va tenir sis polls xics, pics, pellarics, camacurts i becarics. Si la polla no hagués sigut xica, pica, pellarica, camatorta i becarica, els sis polls no haurien sigut xics, pics, pellarics, camacurts i becarics.", "ca", "ca"] ] ) iface.launch(server_name="0.0.0.0", server_port=7860)