Openfst 是一个有限状态机转换器类库。
Openfst 广泛应用于语音识别,语音合成,机器翻译,手写文字识别,模式识别,字符串处理,机器学习,信息提取和检索等等领域。 在语音识别中, 语言模型文法、发音词典、上下文相关声学单元、HMM都可以用FST来表示。
下载 openfst, 编译出错
wget http://www.openfst.org/twiki/pub/FST/FstDownload/openfst-1.6.7.tar.gz
tar xzvf openfst-1.6.7.tar.gz
cd openfst-1.6.7/
./configure --enable-python --enable-far
直接报错, 提示如下:
openfst This version of the AC_PYTHON_DEVEL macro doesn't work properly with versions of Python before 2.1.0. You may need to re-run configure.
改用 openfts 1.8.1 的版本, 编译通过, 我的 Python 环境是 3.9.7。
wget https://www.openfst.org/twiki/pub/FST/FstDownload/openfst-1.8.1.tar.gz
tar zxvf openfst-1.8.1.tar.gz
cd openfst-1.8.1
./configure --enable-python --enable-far
make
sudo make install
# copy package to my virtual python environment:
cp /usr/local/lib/python3.9/site-packages/pywrapfst.* ~/miniforge3/envs/mlp/lib/python3.9/site-packages/
Python 示例,验证 openfst 以及 python 扩展是否安装成功:
import pywrapfst as fst
s = t.add_state()
t.add_arc(s, fst.Arc(97, 97, 1, 2))
f = fst.VectorFst()
one = fst.Weight.one(f.weight_type())
f.reserve_states(3) # Optional.
s = f.add_state()
f.set_start(s)
n = f.add_state()
f.reserve_arcs(s, 1) # Optional.
f.add_arc(s, fst.Arc(98, 98, one, n))
s = n
n = f.add_state()
f.add_arc(s, fst.Arc(97, 97, one, n))
s = n
n = f.add_state()
f.add_arc(s, fst.Arc(97, 97, one, n))
f.set_final(n, one)
f.verify() # Checks FST's sanity
print(f)
# FSTs can also be written to a GraphViz file using the draw instance method.
f.draw("f.gv")
# FSTs can be written to disk using the write instance method.
f.write("f.fst")
参考:
https://gist.github.com/0xnurl/6f97eb39409ea48db31fe315fd1e208f