OpenFST 示例 & Mac 编译安装 - 需要 Python >= 2.1.0 的错误消息处理

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

https://www.openfst.org/twiki/bin/view/FST/PythonExtension

Could not solve for environment specs The following packages are incompatible ├─ pin-1 is installable and it requires │ └─ python 3.10.* , which can be installed; ├─ pytorch-cuda 12.1** is requested and can be installed; ├─ pytorch 2.1.2 is installable with the potential options │ ├─ pytorch [2.1.0|2.1.2] would require │ │ └─ pytorch-cuda >=11.8,<11.9 , which conflicts with any installable versions previously reported; │ ├─ pytorch [2.1.0|2.1.2] would require │ │ └─ python >=3.11,<3.12.0a0 , which conflicts with any installable versions previously reported; │ ├─ pytorch [2.1.0|2.1.2] would require │ │ └─ python >=3.8,<3.9.0a0 , which conflicts with any installable versions previously reported; │ ├─ pytorch [2.1.0|2.1.2] would require │ │ └─ python >=3.9,<3.10.0a0 , which conflicts with any installable versions previously reported; │ └─ pytorch 2.1.2, which can be installed; └─ torchtext 0.16.0** is not installable because there are no viable options ├─ torchtext 0.16.0 would require │ └─ pytorch 2.1.0 but there are no viable options │ ├─ pytorch 2.1.0 conflicts with any installable versions previously reported; │ ├─ pytorch [2.1.0|2.1.2], which cannot be installed (as previously explained); │ ├─ pytorch [2.1.0|2.1.2], which cannot be installed (as previously explained); │ ├─ pytorch [2.1.0|2.1.2], which cannot be installed (as previously explained); │ └─ pytorch [2.1.0|2.1.2], which cannot be installed (as previously explained); ├─ torchtext 0.16.0 would require │ └─ python >=3.11,<3.12.0a0 , which conflicts with any installable versions previously reported; ├─ torchtext 0.16.0 would require │ └─ python >=3.8,<3.9.0a0 , which conflicts with any installable versions previously reported; └─ torchtext 0.16.0 would require └─ python >=3.9,<3.10.0a0 , which conflicts with any installable versions previously reported.
最新发布
03-29
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值