Skip to content

Instantly share code, notes, and snippets.

@korakot
Last active February 16, 2019 11:55
Show Gist options
  • Save korakot/8b941f55ce707f3c6f4dd4ae1e60b6ae to your computer and use it in GitHub Desktop.
Save korakot/8b941f55ce707f3c6f4dd4ae1e60b6ae to your computer and use it in GitHub Desktop.
thpronun wrapper for use in python
!apt install libthai-dev help2man
!wget ftp://linux.thai.net/pub/thailinux/software/thpronun/thpronun-0.2.0.tar.xz
!tar xf thpronun-0.2.0.tar.xz
%cd thpronun-0.2.0
!./configure --prefix=/usr
!make
!make install
import subprocess
from ast import literal_eval
def thpronun(word, output='t', lattice=False):
cmd = ['thpronun', '-'+output]
if lattice:
cmd.append('-g')
cmd.append(word)
res = subprocess.check_output(cmd)
lines = res.decode().strip().split('\n')
if lattice:
return literal_eval(lines[1])
else:
return lines[1:]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment