基于Python PaddleSpeech怎么实现语音文字处理
基于Python PaddleSpeech怎么实现语音文字处理
基于PythonPaddleSpeech怎么实现语音文字处理,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
环境安装
首先我们看一下项目结构以及安装文档。
需要Python3.7以上、C++环境、requirements安装等等,下面按照我的顺序说一下。
1、conda安装Python3.9虚拟环境
使用conda安装python3.9环境,命令如下。
condacreate-npy39python=3.9
2、安装Visual Studio 2019
安装地址: Microsoft C++ 生成工具 - Visual Studio
注意安装的时候需要勾选C++桌面开发。
3、安装requirements.txt
使用命令安装requiremets.txt,命令如下:
pipinstall-rrequirements.txt-ihttps://pypi.douban.com/simple
这里要注意一下,paddlespeech_ctcdecoders安装失败的话无所谓,可以略掉。
4、安装paddlepaddle和paddlespeech
命令如下:
pipinstallpaddlepaddle-ihttps://mirror.baidu.com/pypi/simplepipinstallpaddlespeech-ihttps://pypi.tuna.tsinghua.edu.cn/simple
5、nltk_data下载
按照项目安装文档内的说明。
我的本地目录地址如下
项目验证
我下面分别验证一下tts、asr以及标点恢复功能。
tts语音合成
使用命令如下:
paddlespeechtts--input"南京现在很冷,下次再去夫子庙吧。"--outputC:\Users\xxx\Desktop\115.wav
执行过程
(dh_partner)D:\spyder\PaddleSpeech>paddlespeechtts--input"南京现在很冷,下次再去夫子庙吧。"--outputC:\Users\xxx\Desktop\115.wavphones_dict:None[2022-01-0517:23:43,642][INFO][log.py][L57]-FileC:\Users\huyi\.paddlespeech\models\fastspeech3_csmsc-zh\fastspeech3_nosil_baker_ckpt_0.4.zipmd5checking...[2022-01-0517:23:44,742][INFO][log.py][L57]-Usepretrainedmodelstoredin:C:\Users\huyi\.paddlespeech\models\fastspeech3_csmsc-zh\fastspeech3_nosil_baker_ckpt_0.4self.phones_dict:C:\Users\huyi\.paddlespeech\models\fastspeech3_csmsc-zh\fastspeech3_nosil_baker_ckpt_0.4\phone_id_map.txt[2022-01-0517:23:44,743][INFO][log.py][L57]-C:\Users\huyi\.paddlespeech\models\fastspeech3_csmsc-zh\fastspeech3_nosil_baker_ckpt_0.4[2022-01-0517:23:44,744][INFO][log.py][L57]-C:\Users\huyi\.paddlespeech\models\fastspeech3_csmsc-zh\fastspeech3_nosil_baker_ckpt_0.4\default.yaml[2022-01-0517:23:44,744][INFO][log.py][L57]-C:\Users\huyi\.paddlespeech\models\fastspeech3_csmsc-zh\fastspeech3_nosil_baker_ckpt_0.4\snapshot_iter_76000.pdzself.phones_dict:C:\Users\huyi\.paddlespeech\models\fastspeech3_csmsc-zh\fastspeech3_nosil_baker_ckpt_0.4\phone_id_map.txt[2022-01-0517:23:44,745][INFO][log.py][L57]-FileC:\Users\huyi\.paddlespeech\models\pwgan_csmsc-zh\pwg_baker_ckpt_0.4.zipmd5checking...[2022-01-0517:23:44,782][INFO][log.py][L57]-Usepretrainedmodelstoredin:C:\Users\huyi\.paddlespeech\models\pwgan_csmsc-zh\pwg_baker_ckpt_0.4[2022-01-0517:23:44,783][INFO][log.py][L57]-C:\Users\huyi\.paddlespeech\models\pwgan_csmsc-zh\pwg_baker_ckpt_0.4[2022-01-0517: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-0517:23:44,785][INFO][log.py][L57]-C:\Users\huyi\.paddlespeech\models\pwgan_csmsc-zh\pwg_baker_ckpt_0.4\pwg_snapshot_iter_400000.pdzvocab_size:268frontenddone!encoder_typeistransformerdecoder_typeistransformerC:\Users\huyi\.conda\envs\dh_partner\lib\site-packages\paddle\framework\io.py:415:DeprecationWarning:UsingorimportingtheABCsfrom'collections'insteadoffrom'collections.abc'isdeprecatedsincePython3.3,andin3.10itwillstopworkingifisinstance(obj,collections.Iterable)andnotisinstance(obj,(acousticmodeldone!vocdone!Buildingprefixdictfromthedefaultdictionary...[2022-01-0517:23:51][DEBUG][__init__.py:113]Buildingprefixdictfromthedefaultdictionary...LoadingmodelfromcacheC:\Users\huyi\AppData\Local\Temp\jieba.cache[2022-01-0517:23:51][DEBUG][__init__.py:132]LoadingmodelfromcacheC:\Users\huyi\AppData\Local\Temp\jieba.cacheLoadingmodelcost0.659seconds.[2022-01-0517:23:52][DEBUG][__init__.py:164]Loadingmodelcost0.659seconds.Prefixdicthasbeenbuiltsuccessfully.[2022-01-0517:23:52][DEBUG][__init__.py:166]Prefixdicthasbeenbuiltsuccessfully.C:\Users\huyi\.conda\envs\dh_partner\lib\site-packages\paddle\fluid\dygraph\math_op_patch.py:251:UserWarning:Thedtypeofleftandrightvariablesarenotthesame,leftdtypeispaddle.int64,butrightdtypeispaddle.int32,therightdtypewillconverttopaddle.int64warnings.warn([2022-01-0517:23:58,811][INFO][log.py][L57]-Wavefilehasbeengenerated:C:\Users\xxx\Desktop\115.wav
生成的音频如下
asr语音识别
我就使用了tts生成的音频进行asr识别,看看效果,命令如下:
paddlespeechasr--langzh--inputC:\Users\xxx\Desktop\115.wav
执行结果如下
可以看到最后打印的内容是没有标点的文字输出,还是比较准的。
标点恢复
就用这句话试试标点恢复的情况,命令如下:
paddlespeechtext--taskpunc--input南京现在很冷下次再去夫子庙吧
执行结果
关于基于PythonPaddleSpeech怎么实现语音文字处理问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。
推荐阅读
-
Lightly IDE 快捷键:Python 开发者必学的效率提升操作
-
GitHub Codespaces 模板配置:快速初始化项目环境的技巧
-
Python 类型注解进阶:mypy 静态类型检查与 IDE 集成
-
Python 3.12 模式匹配增强:结构分解与多分支逻辑简化实战
-
Lightly IDE 快捷键定制:Python 开发者专属效率提升方案
-
Python 装饰器高级用法:类装饰器与元类结合实践
-
Python 生成器表达式优化:内存占用与迭代效率平衡技巧
-
Python 类型注解深度:Protocol 协议与泛型类型约束实践
-
Python 3.12 新特性解析:模式匹配增强与性能优化实战
-
Lightly IDE 深度评测:轻量级 Python 开发工具是否适合团队协作?