目录
概要
2017年4月,谷歌发表了论文Tacotron: Towards End-to-End Speech Synthesis,他们提出了一种神经文本到语音模型,该模型可以学习直接从(文本,音频)对中合成语音。 但是,他们没有发布源代码或训练数据,这里是基于GitHub上一个tacotron模型的实现展开研究的。GitHub网址:https://github.com/keithito/tacotron
一. 模型下载与安装
- 下载tacotron模型到本地
- 本研究是在linux平台下开展的,使用虚拟机来搭建Ubuntu,并安装了Anaconda。下面展示了tacotron的源码文件。
- 安装一些依赖项:
① 安装Python 3
# 使用Anaconda安装Python3环境
conda create --name python36 python=3.6
② 安装TensorFlow,这里安装的版本是tensorflow==1.15.0,其它2.0或更高版本可能会出现意想不到的问题。建议先安装③,再安装②,否则可能会有问题!!!
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow==1.15.0 #实测安装这个版本不会出现问题
③ 安装此模型的一些要求:pip install -r requirements.txt
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
-
requirements.txt 文件:
-
注意
:建议安装过程中尽量还是按顺序单独安装,安装librosa时会附带安装numpy 1.19.1和scipy 1.5.2。本次实现是单独安装的,因为直接安装全部的要求在测试的时候出现了问题。
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple falcon==1.2.0
>>>
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple inflect==0.2.5
>>>
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple librosa==0.5.1 # 附带安装了numpy和scipy
>>>
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple matplotlib==2.0.2
>>>
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tqdm==4.11.2
>>>
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple Unidecode==0.4.20
- 安装过程:
二. 使用预训练模型
1. 基于linux平台——使用预先训练好的模型来进行语音合成
- 下载并解压模型:
curl http://data.keithito.com/data/speech/tacotron-20180906.tar.gz | tar xzC /tmp
注
:也可以将模型单独下载之后,添加到tacotron-master的目录中
- 运行demo_server.py代码程序
python3 demo_server.py --checkpoint ./tmp/tacotron-20180906/model.ckpt # 注意tmp的路径,刚开始就是路径没写对,一直打不开浏览器。./表示当前目录
- 运行过程
- 将浏览器指向localhost:9000,输入文本内容,输出合成的语音。即执行完第4步骤之后,打开浏览器,输入localhost:9000,会出现如下页面。
-
执行TTS过程。输入要合成的文本,输出合成的语音:
-
合成结果:
2. 基于windows平台
- 依赖项的安装参考 一. 模型下载与安装 相同步骤,python环境为 python36 ,后面训练时要使用。
-
进入代码目录,并激活环境
-
运行demo_server.py代码程序
python demo_server.py --checkpoint ./tmp/tacotron-20180906/model.ckpt # 注意tmp的路径。./表示当前目录
- 运行过程
- 将浏览器指向localhost:9000,输入文本内容,输出合成的语音。即执行完第2步骤之后,打开浏览器,输入localhost:9000,会出现如下页面。
-
执行TTS过程。输入要合成的文本,输出合成的语音:
-
合成结果:
三. 训练模型
训练步骤
1. 使用其他数据,训练,合成语音
①下载语音数据集LJ Speech(LJ语音数据集);
②将数据集解压到 ./tacotron(./表示当前目录)
③解压后,对于LJ语音,对应的树如下所示:
2. 预处理数据
python3 preprocess.py --dataset ljspeech
- 在预处理模型的过程中,python3 preprocess.py --dataset ljspeech出现了问题,
ValueError: operands could not be broadcast together with shapes (1,1025) (0,)
。这里重新拷贝了一. 模型下载与安装的python36环境,命名为 python36-copy ,并卸载了librosa之后,重新安装了 librosa==0.8.0 解决了问题。 - 问题截图:
- 成功运行
- 运行结束后,会在training文件夹里生成很多.npy文件和一个train.txt文件,其文件会在 3.训练模型的过程中被使用。
3. 训练模型
python3 train.py # 默认1000个step保存模型
或者
python3 train.py --checkpoint_interval 200 # 指定每200个step保存模型
- 问题
注意:
在使用预处理的 python36-copy 环境训练模型的过程中出现了问题Exiting due to exception: module 'scipy' has no attribute 'io'
,如下图:
- 解决办法
解决:
使用 一. 模型下载与安装 中的 python36 环境,解决了问题,如下图测试结果。
python3 train.py --checkpoint_interval 2 # 指定每2个step保存模型
- 成功训练模型
4. 从一个checkpoint合成语音
python3 demo_server.py --checkpoint ~/tacotron/logs-tacotron/model.ckpt-185000
- 将“185000”替换为要使用的检查点编号,然后打开浏览器到localhost:9000并键入您要说的内容,即可合成语音。
- 或者,可以在命令行运行eval.py:
python3 eval.py --checkpoint ~/tacotron/logs-tacotron/model.ckpt-185000