传送门
《iOS-PocketSphinx——安装PocketSphinx》
《iOS-PocketSphinx——构建iOS使用的SDK》
当前文章:《iOS-PocketSphinx——安装g2p-seq2seq》
系统环境
Mac OS 10.15.7
下载工具:g2p-seq2seq
安装前准备
- 如果没安装
wget
,则安装(安装顺利)
$ brew install wget
- 如果没安装
pip
,则安装(安装顺利)
$ wget https://bootstrap.pypa.io/get-pip.py
- 如果没安装
tensor2tensor
,则安装(安装出错自己解决)
$ sudo pip3 install tensor2tensor
- 如果没安装
tensorflow
,则安装(我这边各种报错,参考《安装tensorflow的坎坷过程》)
更新python版本
从Python官网下载python3.6.0
安装完后,终端查下版本
$ python3 -V
$ Python 3.6.0
安装g2p-seq2seq
$ sudo python3 setup.py install
报错
Running tqdm-4.58.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-c6of5sz0/tqdm-4.58.0/egg-dist-tmp-cmrflq36
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'use_scm_version'
warnings.warn(msg)
warning: install_lib: 'build/lib' does not exist -- no Python modules to install
zip_safe flag not set; analyzing archive contents...
Copying UNKNOWN-0.0.0-py3.6.egg to /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
Adding UNKNOWN 0.0.0 to easy-install.pth file
Installed /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/UNKNOWN-0.0.0-py3.6.egg
error: The 'tqdm' distribution was not found and is required by tensor2tensor
安装g2p-seq2seq
$ cd /Users/.../g2p-seq2seq
$ sudo python setup.py install
- python版本要大于等于3.7,否则报如下错误
RuntimeError: Python version >= 3.7 required.
使用g2p-seq2seq扩展字典
到这里下载训练好的模型:
https://sourceforge.net/projects/cmusphinx/files/G2P%20Models/
g2p-seq2seq-model-5.2-cmudict.tar.gz
zh.tar.gz
cd到g2p-seq2seq-cmudict所在目录
$ cd /Users/Aaron/iOS/G2P
$ g2p-seq2seq --interactive --model_dir g2p-seq2seq-cmudict
报错1
$ g2p-seq2seq --interactive --model_dir g2p-seq2seq-cmudict
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/bin/g2p-seq2seq", line 33, in <module>
sys.exit(load_entry_point('g2p-seq2seq==6.2.2a0', 'console_scripts', 'g2p-seq2seq')())
File "/Library/Frameworks/Python.framework/Versions/3.9/bin/g2p-seq2seq", line 25, in importlib_load_entry_point
return next(matches).load()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/metadata.py", line 77, in load
module = import_module(match.group('module'))
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/g2p_seq2seq-6.2.2a0-py3.9.egg/g2p_seq2seq/__init__.py", line 24, in <module>
from g2p_seq2seq import app
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/g2p_seq2seq-6.2.2a0-py3.9.egg/g2p_seq2seq/app.py", line 29, in <module>
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
看样子得tensorflow,安装过程也是各种报错,一步一步解决太坎坷了,解决过程太久,请移步另一篇文章:安装tensorflow的坎坷过程
但是g2p-seq2seq还是报错
$ cd /Users/Aaron/iOS/G2P
$ g2p-seq2seq --interactive --model_dir g2p-seq2seq-cmudict
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/bin/g2p-seq2seq", line 33, in <module>
sys.exit(load_entry_point('g2p-seq2seq==6.2.2a0', 'console_scripts', 'g2p-seq2seq')())
File "/Library/Frameworks/Python.framework/Versions/3.6/bin/g2p-seq2seq", line 25, in importlib_load_entry_point
return next(matches).load()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/importlib_metadata/__init__.py", line 100, in load
module = import_module(match.group('module'))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 936, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/g2p_seq2seq-6.2.2a0-py3.6.egg/g2p_seq2seq/__init__.py", line 24, in <module>
from g2p_seq2seq import app
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/g2p_seq2seq-6.2.2a0-py3.6.egg/g2p_seq2seq/app.py", line 31, in <module>
import g2p_seq2seq.g2p_trainer_utils as g2p_trainer_utils
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/g2p_seq2seq-6.2.2a0-py3.6.egg/g2p_seq2seq/g2p_trainer_utils.py", line 26, in <module>
from tensorflow.contrib.learn.python.learn import learn_runner
ModuleNotFoundError: No module named 'tensorflow.contrib'
网上说
tensorflow 2.0以后没有 tensorflow.contrib
于是
$ pip uninstall tensorflow #卸载tensorflow
$ pip install tensorflow==1.14.0 #安装tensorflow 1.13.1
再试一下g2p-seq2seq,接着继续报错
$ cd /Users/Aaron/iOS/G2P
$ g2p-seq2seq --interactive --model_dir g2p-seq2seq-cmudict
···省略一大堆日志···
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensor2tensor-1.7.0-py3.6.egg/tensor2tensor/data_generators/speech_recognition.py", line 26, in <module>
from scipy.io import wavfile
ModuleNotFoundError: No module named 'scipy'
$ pip3 install --default-timeout=1000 scipy -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/
然后看到安装成功
Successfully installed scipy-1.5.4
再试一下g2p-seq2seq,接着报这个错(GitHub关联错误)
$ g2p-seq2seq --interactive --model_dir g2p-seq2seq-cmudict
···省略一大堆代码···
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
参考资料:
建立语音字典(官方教程):https://cmusphinx.github.io/wiki/tutorialdict/#introduction
g2p-seq2seq(工具):https://github.com/cmusphinx/g2p-seq2seq
G2P(单词到音素)的深度学习训练测试:https://blog.csdn.net/sparkexpert/article/details/51732786
Mac改终端python运行版本:https://jingyan.baidu.com/article/4f7d571207bdc61a201927ca.html
MAC系统更改python版本:https://www.jianshu.com/p/def1cba62f16