File size: 1,068 Bytes
3d783a8
664d5a5
 
3d783a8
664d5a5
3d783a8
664d5a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import phonetisaurus
from collections import namedtuple

model = phonetisaurus.Phonetisaurus(model="./model.fst")

def Phoneticize (args) :
    
    results = model.Phoneticize (
        args["token"],
        args["nbest"],
        args["beam"],
        args["thresh"],
        args["write_fsts"],
        args["accumulate"],
        args["pmass"]
    )

    for result in results :
        uniques = [model.FindOsym (u) for u in result.Uniques]
        return "".join(uniques)

    return ""


def phonemizer(text: str):
    
    if not text:
        return ""
    
    args = {
        "token": text,
        "word": "word",
        "nbest": 1,
        "thresh": 10.0,
        "write_fsts": False,
        "accumulate": False,
        "pmass": 0.0,
        "beam": 500
    }

    return f"/{Phoneticize(args)}/"

iface = gr.Interface(
    title="Khmer Phonemizer",
    description="Convert Khmer & English into Phonetic Symbols",
    fn=phonemizer, inputs="text", 
    outputs="text",
    allow_flagging="never",
)

iface.launch(show_api=False)