Spaces:
Running
Running
File size: 955 Bytes
9b2107c |
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 |
import os
finder = None
def init():
try:
import jpype
import jpype.imports
except ModuleNotFoundError:
raise ModuleNotFoundError(
"Belarusian phonemizer requires to install module 'jpype1' manually. Try `pip install jpype1`."
)
try:
jar_path = os.environ["BEL_FANETYKA_JAR"]
except KeyError:
raise KeyError("You need to define 'BEL_FANETYKA_JAR' environment variable as path to the fanetyka.jar file")
jpype.startJVM(classpath=[jar_path])
# import the Java modules
from org.alex73.korpus.base import GrammarDB2, GrammarFinder
grammar_db = GrammarDB2.initializeFromJar()
global finder
finder = GrammarFinder(grammar_db)
def belarusian_text_to_phonemes(text: str) -> str:
# Initialize only on first run
if finder is None:
init()
from org.alex73.fanetyka.impl import FanetykaText
return str(FanetykaText(finder, text).ipa)
|