欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

基于Python PaddleSpeech实现语音文字处理

程序员文章站 2022-01-09 11:31:18
目录前言环境安装项目验证tts语音合成asr语音识别标点恢复总结前言这段时间一直在研究飞浆平台,最近试了试paddlespeech项目,试着对文本语音做处理。整体的效果个人觉着不算特别优越,只能作为简...

前言

这段时间一直在研究飞浆平台,最近试了试paddlespeech项目,试着对文本语音做处理。整体的效果个人觉着不算特别优越,只能作为简单的学习使用。

项目github地址:github仓库

环境安装

首先我们看一下项目结构以及安装文档。

基于Python PaddleSpeech实现语音文字处理

需要python3.7以上、c++环境、requirements安装等等,下面按照我的顺序说一下。

1、conda安装python3.9虚拟环境

使用conda安装python3.9环境,命令如下。

conda create -n py39 python=3.9

2、安装visual studio 2019

安装地址: microsoft c++ 生成工具 - visual studio

注意安装的时候需要勾选c++桌面开发。

3、安装requirements.txt

使用命令安装requiremets.txt,命令如下:

pip install -r requirements.txt -i https://pypi.douban.com/simple

这里要注意一下,paddlespeech_ctcdecoders安装失败的话无所谓,可以略掉。

4、安装paddlepaddle和paddlespeech

命令如下:

pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
pip install paddlespeech -i https://pypi.tuna.tsinghua.edu.cn/simple

5、nltk_data下载

按照项目安装文档内的说明。

基于Python PaddleSpeech实现语音文字处理

我的本地目录地址如下

基于Python PaddleSpeech实现语音文字处理

项目验证

我下面分别验证一下tts、asr以及标点恢复功能。

tts语音合成

使用命令如下:

paddlespeech tts --input "南京现在很冷,下次再去夫子庙吧。" --output c:\users\xxx\desktop\115.wav

执行过程

(dh_partner) d:\spyder\paddlespeech>paddlespeech tts --input "南京现在很冷,下次再去夫子庙吧。" --output c:\users\xxx\desktop\115.wav
phones_dict: none
[2022-01-05 17:23:43,642] [    info] [log.py] [l57] - file c:\users\huyi\.paddlespeech\models\fastspeech2_csmsc-zh\fastspeech2_nosil_baker_ckpt_0.4.zip md5 checking...
[2022-01-05 17:23:44,742] [    info] [log.py] [l57] - use pretrained model stored in: c:\users\huyi\.paddlespeech\models\fastspeech2_csmsc-zh\fastspeech2_nosil_baker_ckpt_0.4
self.phones_dict: c:\users\huyi\.paddlespeech\models\fastspeech2_csmsc-zh\fastspeech2_nosil_baker_ckpt_0.4\phone_id_map.txt
[2022-01-05 17:23:44,743] [    info] [log.py] [l57] - c:\users\huyi\.paddlespeech\models\fastspeech2_csmsc-zh\fastspeech2_nosil_baker_ckpt_0.4
[2022-01-05 17:23:44,744] [    info] [log.py] [l57] - c:\users\huyi\.paddlespeech\models\fastspeech2_csmsc-zh\fastspeech2_nosil_baker_ckpt_0.4\default.yaml
[2022-01-05 17:23:44,744] [    info] [log.py] [l57] - c:\users\huyi\.paddlespeech\models\fastspeech2_csmsc-zh\fastspeech2_nosil_baker_ckpt_0.4\snapshot_iter_76000.pdz
self.phones_dict: c:\users\huyi\.paddlespeech\models\fastspeech2_csmsc-zh\fastspeech2_nosil_baker_ckpt_0.4\phone_id_map.txt
[2022-01-05 17:23:44,745] [    info] [log.py] [l57] - file c:\users\huyi\.paddlespeech\models\pwgan_csmsc-zh\pwg_baker_ckpt_0.4.zip md5 checking...
[2022-01-05 17:23:44,782] [    info] [log.py] [l57] - use pretrained model stored in: c:\users\huyi\.paddlespeech\models\pwgan_csmsc-zh\pwg_baker_ckpt_0.4
[2022-01-05 17:23:44,783] [    info] [log.py] [l57] - c:\users\huyi\.paddlespeech\models\pwgan_csmsc-zh\pwg_baker_ckpt_0.4
[2022-01-05 17:23:44,783] [    info] [log.py] [l57] - c:\users\huyi\.paddlespeech\models\pwgan_csmsc-zh\pwg_baker_ckpt_0.4\pwg_default.yaml
[2022-01-05 17:23:44,785] [    info] [log.py] [l57] - c:\users\huyi\.paddlespeech\models\pwgan_csmsc-zh\pwg_baker_ckpt_0.4\pwg_snapshot_iter_400000.pdz
vocab_size: 268
frontend done!
encoder_type is transformer
decoder_type is transformer
c:\users\huyi\.conda\envs\dh_partner\lib\site-packages\paddle\framework\io.py:415: deprecationwarning: using or importing the abcs from 'collections' instead of from 'collections.abc' i
s deprecated since python 3.3, and in 3.10 it will stop working
  if isinstance(obj, collections.iterable) and not isinstance(obj, (
acoustic model done!
voc done!
building prefix dict from the default dictionary ...
[2022-01-05 17:23:51] [debug] [__init__.py:113] building prefix dict from the default dictionary ...
loading model from cache c:\users\huyi\appdata\local\temp\jieba.cache
[2022-01-05 17:23:51] [debug] [__init__.py:132] loading model from cache c:\users\huyi\appdata\local\temp\jieba.cache
loading model cost 0.659 seconds.
[2022-01-05 17:23:52] [debug] [__init__.py:164] loading model cost 0.659 seconds.
prefix dict has been built successfully.
[2022-01-05 17:23:52] [debug] [__init__.py:166] prefix dict has been built successfully.
c:\users\huyi\.conda\envs\dh_partner\lib\site-packages\paddle\fluid\dygraph\math_op_patch.py:251: userwarning: the dtype of left and right variables are not the same, left dtype is padd
le.int64, but right dtype is paddle.int32, the right dtype will convert to paddle.int64
  warnings.warn(
[2022-01-05 17:23:58,811] [    info] [log.py] [l57] - wave file has been generated: c:\users\xxx\desktop\115.wav

生成的音频如下

基于Python PaddleSpeech实现语音文字处理

asr语音识别

我就使用了tts生成的音频进行asr识别,看看效果,命令如下:

paddlespeech asr --lang zh --input c:\users\xxx\desktop\115.wav

执行结果如下

基于Python PaddleSpeech实现语音文字处理

可以看到最后打印的内容是没有标点的文字输出,还是比较准的。

标点恢复

就用这句话试试标点恢复的情况,命令如下:

paddlespeech text --task punc --input 南京现在很冷下次再去夫子庙吧

执行结果

基于Python PaddleSpeech实现语音文字处理

看起来语义上没什么问题。

总结

我在前言中说效果不是很好的主要原因是因为速率比较慢,相比于类似阿里云提供的tts、asr接口来说,效率比较低。也可能和需要校验模型是否存在这些无关紧要的功能有关。可以考虑研究代码,自己重新封装一些服务,效果应该好的多。

到此这篇关于基于python paddlespeech实现语音文字处理的文章就介绍到这了,更多相关python paddlespeech语音文字处理内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!