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. repo: https://github.com/projecte-aina/espeak-ng/tree/dev-ca """ article= "" iface = gr.Interface( fn=phonemiser, inputs=[ gr.Textbox( label="Text", value="Les coses importants són les que no ho semblen.", ), 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=[ ["Les coses importants són les que no ho semblen.", "ca", "ca"], ["Les coses importants són les que no ho semblen.", "ca-va", "ca-va"], ["Les coses importants són les que no ho semblen.", "ca-nw", "ca-nw"], ["Ses coses importants són ses que no ho semblen.", "ca-ba", "ca-ba"] ] ) iface.launch(server_name="0.0.0.0", server_port=7860)