环境:本机windows系统,cuda版本11.1

paddlespeech要求(来源github)

所以在anaconda中创建py3.9环境,关于gcc的安装还会碰到以下问题。

Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/

所以我们去Microsoft C++ Build Tools - Visual Studio

下载visualstudio

anacoda中创建python环境

#在anaconda prompt中

conda create -n test python=3.7

conda activate py39

 请务必查看自己的cuda版本,才能安装对应版本的paddle

参考网站飞桨PaddlePaddle-源于产业实践的开源深度学习平台

所以按本机环境要求只能安装2.3的paddle版本

#在anaconda prompt中先安装runner
pip install pytest-runner -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install paddlepaddle-gpu==2.3.2.post111 -f https://www.paddlepaddle.org.cn/whl/windows/mkl/avx/stable.html
pip install paddlespeech -i https://pypi.tuna.tsinghua.edu.cn/simple

以上完成安装步骤。我们找到一个参考音频:

https://paddlespeech.bj.bcebos.com/PaddleAudio/ch_zh_mix.wav

然后使用代码的方式来运行测试用例:

import paddle
from paddlespeech.cli.asr import ASRExecutor
import warnings
warnings.filterwarnings("ignore")

asr_executor = ASRExecutor()
text = asr_executor(
    model='conformer_talcs',
    lang='zh_en',
    sample_rate=16000,
    config=None, 
    ckpt_path=None,
    audio_file='./ch_zh_mix.wav',
    codeswitch=True,
    force_yes=False,
    device=paddle.get_device())
print('ASR Result: \n{}'.format(text))

不出意外就会有一个bug:

AttributeError: module 'numpy' has no attribute 'complex'.

解决方法:降低numpy版本 或者更改源码

方法一:numpy 1.26.2 => 1.20
方法二:定位到使用complex的地方。本错误是在 constantq.py的1059行
把这一行的dtype=np.complex改成dtype=np.complex128

解决上述问题后,会有一个新的问题:

declarative() got an unexpected keyword argument 'property'

解决方法:没有更好的解决方法,只能更改源码

这个bug可以定位到subsamping_rate文件中这是一个非py文件,搜索“property=True”可以找到五处,
把这五处的property=True全部删除

到这里就没有错误了

显示输出结果:

拓展:我们也希望能够实现语气识别,给输出的句子加上标点符号。这里就需要用到TextExecutor模块,更改代码为

import paddle
from paddlespeech.cli.asr import ASRExecutor
from paddlespeech.cli.text import TextExecutor
import warnings
warnings.filterwarnings("ignore")

asr_executor = ASRExecutor()
text_punc = TextExecutor()
text = asr_executor(
    model='conformer_talcs',
    lang='zh_en',
    sample_rate=16000,
    config=None, 
    ckpt_path=None,
    audio_file='./ch_zh_mix.wav',
    codeswitch=True,
    force_yes=False,
    device=paddle.get_device())
print('ASR Result: \n{}'.format(text))
result2=text_punc (text,task='punc')
print('TextExecutor Result: \n{}'.format(text))
print(result2)

不出意外,这里又有一个新的bug:

ModuleNotFoundError: No module named 'paddle.nn.layer.layers'

这个问题源于paddlenlp的版本问题,目前安装paddlepaddle都会自动安装最新版paddlenlp,这样会导致paddlespeech在调用paddle的时候出现版本不兼容。

上图是panddlenlp的要求,可见paddlepaddle2.5之后的api大大更改了

解决方法:降低版本

#palldenlp 2.6.1 => 2.5.2
pip uninstall paddlenlp
pip install paddlenlp==2.5.2

在pip的时候这里有会有一个新的bug:

ppdiffusers 0.19.3 requires paddlenlp>=2.6.0rc0, but you have paddlenlp 2.5.2 which is incompatible.

ppdiffusers是用于多模态的扩散模型,本项目压根用不到,所以不管也行。

于是这里就会有成功的输出:

如果想隐藏除了结果外的其他输出,推荐使用sys模块

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐