PaddleSpeech文本转语音及语音转文本安装

PaddleSpeech是百度人工智能框架下的一个文本语音操作应用,具备工业级的文本与语音空间操作包括但不限于文本转语音,语音转文本,语音复制,声纹提取等功能。paddlespeech整体安装相对有些复杂,特别是机遇linux下安装,这里先以windows下通过cuda+python进行体验式安装过程。

准备环境(window10,没装git的需要先安装git环境)
1.python10
2.C++编译环境
3.cuda 11.7
4.cudnn 8.6
5.paddlepaddle-gpu 2.4.2.post117
6.paddlespeech 1.4.0

一. python10安装
这个安装很简单,直接上官网下载window版本的安装器傻瓜式next安装即可,官网地址:https://www.python.org/downloads/windows/
(python环境最好是通过ancoda进行管理起来,否则很容易混乱,通过ancoda进行python环境隔离不会影响其他环境)

二.C++编译环境安装
对于 Windows 系统,需要安装 Visual Studio 来完成 C++ 编译环境的安装。
https://visualstudio.microsoft.com/visual-cpp-build-tools/

三.cuda 和cudnn安装
英伟达显卡驱动以及神经网络加速包安装
cuda这里根据驱动版本进行选择安装,本机电脑使用cuda11.7
下载地址:https://developer.nvidia.com/cuda-toolkit-archive
按引导安装完成后,执行
nvcc -V
能查看到版本好即可。

cudnn为升级网络加速包,下载需要登入nvidia平台账号才能下载
下载地址:https://developer.nvidia.cn/zh-cn/cudnn
下载成功后,解压,然后将解压后内容全部复制到
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7
相同文件夹里面
file

四.paddlepaddle-gpu 安装
如果只是想通过cpu安装体验可以直接安装cpu版本的paddle,官网地址(https://www.paddlepaddle.org.cn/
这里本机采用一块RTX 3060TI进行安装
打开cmd,执行:
python -m pip install paddlepaddle-gpu==2.4.2.post117 -f https://www.paddlepaddle.org.cn/whl/windows/mkl/avx/stable.html

等安装过程结束即可。

五.paddlespeech安装
这个安装需要注意一下版本,git上最新的版本和paddle的版本需要对应一下,否则推理过程可能会出现各种异常。这里我们使用1.4.0版本的原编码进行编译,至于为什么用源码编译是因为直接通过pip源安装出错的可能性大大增加。
官方文档安装:
pip install paddlespeech

推荐使用源码安装,找个空目录,右键打开 git bash,将源代码clone下来
git clone --branch r1.4.0 https://github.com/PaddlePaddle/PaddleSpeech.git

进入PaddleSpeech文件夹,执行以下命令

pip install pytest-runner
pip install .

安装完成后可以执行以下命令验证

下载测试音频:https://paddlespeech.bj.bcebos.com/PaddleAudio/zh.wav
执行:paddlespeech asr --lang zh --input ../data/zh.wav 

输出

2023-06-06 23:14:08.282 | INFO     | paddlespeech.s2t.modules.ctc:W0606 23:14:08.285218  9772 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 8.6, Driver API Version: 12.1, Runtime API Version: 11.7
:45 - paddlespeech_ctcdecoders not installed!
W0606 23:14:08.290212  9772 gpu_resources.cc:91] device: 0, cuDNN Version: 8.6.
2023-06-06 23:14:09.840 | INFO     | paddlespeech.s2t.modules.embedding:__init__:150 - max len: 5000
C:\ProgramData\Anaconda3\envs\yolo\lib\site-packages\paddle\fluid\dygraph\math_op_patch.py:275: UserWarning: The dtype of left and right variables are not the same, left dtype is paddle.int64, but right dtype is paddle.bool, the right dtype will convert to paddle.int64
  warnings.warn(
我认为跑步最重要的就是给我带来了身体健康

安装常问题
1.安装paddlespeech错误

error: can't copy 'paddlespeech\t2s\exps\tacotron2\normalize.py': doesn't exist or not a regular file
      [end of output]
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> paddlespeech

或者

   Broadcast dimension mismatch. Operands could not be broadcast together with the shape of X = [1, 1, 0, 498] and the shape of Y = [1, 123, 123]. Received [498] in X is not equal to [123] in Y at i:3

该错误是paddle的版本与paddlespeech版本不一致导致的,一般是speech的版本过高,可以尝试低版本的paddlespeech。

2.cuddn异常

 The third-party dynamic library (cudnn64_8.dll) that Paddle depends on is not configured correctly. (error code is 126

这个异常表示未正确安装cuddn,请严格按照步骤操作,并核对与cuda版本。

3.提升zlibwapi.ddl未找到
Could not locate zlibwapi.dll. Please make sure it is in your library path

推理过程中提升zlibwapi.dll没有的,可以再网上下载一个离线包,将里面的ddl放置咋对应文件夹
file
网上找到一个工程师上传的包
链接:https://pan.baidu.com/s/1JE4D5NQ0MfRkZdAEVQZHVQ
提取码:t4uv