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

 更新时间:2022年01月06日 08:36:59   作者:剑客阿良_ALiang  
PaddleSpeech基于飞桨PaddlePaddle的语音方向的开源模型库,用于语音和音频中的各种关键任务的开发,包含大量基于深度学习前沿和有影响力的模型。本文将介绍如何通过PaddleSpeech实现语音文字处理,感兴趣的可以学习一下

前言

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

项目github地址:github仓库

环境安装

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

需要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下载

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

我的本地目录地址如下

项目验证

我下面分别验证一下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

生成的音频如下

asr语音识别

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

paddlespeech asr --lang zh --input C:\Users\xxx\Desktop\115.wav

执行结果如下

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

标点恢复

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

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

执行结果

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

总结

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

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

相关文章

  • python使用Plotly绘图工具绘制柱状图

    python使用Plotly绘图工具绘制柱状图

    这篇文章主要为大家详细介绍了python使用Plotly绘图工具绘制柱状图,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2019-04-04
  • Python判断素数的3种方法及for-else语句的用法介绍

    Python判断素数的3种方法及for-else语句的用法介绍

    素数又叫质数,指的是>1的整数中,只能被1和这个数本身整除的数,这篇文章主要给大家介绍了关于Python判断素数的3种方法及for-else语句的用法介绍的相关资料,文中通过代码介绍的非常详细,需要的朋友可以参考下
    2024-05-05
  • Python实现迷宫生成器的详细代码

    Python实现迷宫生成器的详细代码

    这篇文章主要介绍了Python实现迷宫生成器的详细代码,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-07-07
  • Python中常见内置函数的用法合集

    Python中常见内置函数的用法合集

    本文将从基础到高级,详细介绍Python中常见的内置函数,通过代码示例和中文注释,帮助您深入理解如何在不同情景下灵活应用这些函数,需要的可以学习一下
    2023-09-09
  • django 发送邮件和缓存的实现代码

    django 发送邮件和缓存的实现代码

    这篇文章主要介绍了django 发送邮件和缓存的实现代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-07-07
  • matplotlib之pyplot模块实现添加子图subplot的使用

    matplotlib之pyplot模块实现添加子图subplot的使用

    这篇文章主要介绍了matplotlib之pyplot模块实现添加子图subplot的使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-04-04
  • 对python:循环定义多个变量的实例详解

    对python:循环定义多个变量的实例详解

    今天小编就为大家分享一篇对python:循环定义多个变量的实例详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2019-01-01
  • Python Pandas条件筛选功能

    Python Pandas条件筛选功能

    这篇文章主要介绍了Python Pandas条件筛选功能,筛选是在平时的工作中使用非常频繁的功能了,下文详细的相关资料介绍,需要的小伙伴可以参考一下
    2022-03-03
  • python之当你发现QTimer不能用时的解决方法

    python之当你发现QTimer不能用时的解决方法

    今天小编就为大家分享一篇python之当你发现QTimer不能用时的解决方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2019-06-06
  • 迁移现有的python项目到pyproject.toml

    迁移现有的python项目到pyproject.toml

    本文将详细介绍将现有的 Python 项目迁移到 pyproject.toml,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2025-04-04

最新评论