File size: 762 Bytes
e4b9a7b | 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 | # -*- coding: utf-8 -*-
# SPDX-FileCopyrightText: 2016-2025 PyThaiNLP Project
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: Apache-2.0
"""
Transliterating text to International Phonetic Alphabet (IPA)
Using International Components for Unicode (ICU)
:See Also:
* `GitHub \
<https://github.com/ovalhub/pyicu>`_
"""
from icu import Transliterator
_ICU_THAI_TO_LATIN = Transliterator.createInstance("Thai-Latin")
def transliterate(text: str) -> str:
"""
Use ICU (International Components for Unicode) for transliteration
:param str text: Thai text to be transliterated.
:return: A string of Internaitonal Phonetic Alphabets indicating how the text should be pronounced.
"""
return _ICU_THAI_TO_LATIN.transliterate(text)
|