paddlespeech asr脚本demo

概述
paddlespeech是百度飞桨平台的开源工具包,主要用于语音和音频的分析处理,其中包含多个可选模型,提供语音识别、语音合成、说话人验证、关键词识别、音频分类和语音翻译等功能。
本文介绍利用ps中的asr功能实现批量处理音频文件的demo。
环境
centos 7.9
Python 3.10.3
paddlepaddle 2.5.1
paddlespeech 1.4.1
demo代码
demo的代码如下,使用python3.10版本运行。
# -*- coding: utf-8 -*-
#required python3.10
###paddlespeech asr demo
# paddlespeech asr -y --lang zh --model conformer_wenetspeech --input $audiofile
### demo基本的业务流程
### 给定目录,扫描目录下的音频文件,对音频文件进行asr接口操作,写入对应的结果文件
import os
from paddlespeech.cli.asr.infer import ASRExecutor
import soundfile as sf
srcPath = r'/home/admin/test'
resultFile = r'/home/admin/test/asr-result-file.txt'
##打开结果文件
rfile = open(resultFile, 'a')
##获取asr对象
asr = ASRExecutor()
for filename in os.listdir(srcPath):
if filename.endswith('.wav') or filename.endswith('.mp3'):
audio_file_path = os.path.join(srcPath, filename)
##获取文件参数,计算音频长度
audio_data, sample_rate = sf.read(audio_file_path)
duration = len(audio_data) / sample_rate
##当前的asr接口不能处理超过50秒的音频文件,自动跳过
if duration >= 50:
resultStr = 'srcFile:{}, duration >= 50, skip.'.format(audio_file_path)
print(resultStr)
rfile.write(resultStr + '\n')
else:
result = asr(audio_file=audio_file_path, model='conformer_wenetspeech', lang='zh', force_yes='y')
print('srcFile:{}, asrResult:{}.'.format(audio_file_path, result))
rfile.write('srcFile:{}, asrResult:{}.\n'.format(audio_file_path, result))
rfile.close()
测试
demo的测试结果如下。
$ python3 ps-asr-demo.py
/usr/local/python3/lib/python3.10/site-packages/librosa/core/constantq.py:1059: DeprecationWarning: `np.complex` is a deprecated alias for the builtin `complex`. To silence this warning, use `complex` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.complex128` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
dtype=np.complex,
2023-09-11 16:10:12.299 | INFO | paddlespeech.s2t.modules.embedding:__init__:150 - max len: 5000
/usr/local/python3/lib/python3.10/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(
srcFile:/home/admin/test/zh.wav, asrResult:我认为跑步最重要的就是给我带来了身体健康.
srcFile:/home/admin/test/en.wav, asrResult:那摘了的标准.
[2023-09-11 16:10:20,223] [ WARNING] - The sample rate of the input file is not 16000.
The program will resample the wav file to 16000.
If the result does not meet your expectations,
Please input the 16k 16 bit 1 channel wav file.
/usr/local/python3/lib/python3.10/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(
srcFile:/home/admin/test/output.wav, asrResult:你好欢迎使用百度非讲深度学习框架.
srcFile:/home/admin/test/test-long-file.mp3, duration >= 50, skip.
...
总结
ps的asr功能中有多个模型可选,目前测试中的“conformer_wenetspeech”识别准确率较高。
识别速度有待提高,音频长度的限制也待解决。
空空如常
求真得真
paddlespeech asr脚本demo的更多相关文章
- paddlespeech asr 使用教程
目录 安装 paddle框架安装 软件源安装 源码安装 快速使用 下载测试使用的音频 非流式命令行接口(CLI) 非流式Server服务 流式Server服务 指令详解 打印paddlespeech_ ...
- Appium之开发计算器自动化测试脚本Demo
1.依赖包 <!-- https://mvnrepository.com/artifact/io.appium/java-client --> <dependency> < ...
- oozie调度hive脚本demo
1. 环境配置 2. 脚本配置 3. 执行job 4. 查看结果 待发布 ..
- 基于python3.7的一个闯越自动签到脚本--demo版
望指正demo的定位,有时候会抽风无法接受我的定位信息 #! /usr/bin/python3 # -*- coding:UTF- -*- # time : // : # file : chuangy ...
- 验证销售部门的数据查看权限-脚本demo
1 # coding:utf-8 2 ''' 3 @file: run_old.py 4 @author: jingsheng hong 5 @ide: PyCharm 6 @createTime: ...
- appium+Python真机运行测试demo的方法
appium+Python真机运行测试demo的方法 一, 打开手机的USB调试模式 二, 连接手机到电脑 将手机用数据线连接到电脑,并授权USB调试模式.查看连接的效果,在cmd下运行命 ...
- 将表数据生成Insert脚本
set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgo-- =============================================-- Author ...
- PowerShell 脚本执行策略
为防止恶意脚本的执行,PowerShell 中设计了一个叫做执行策略(Execution Policy)的东西(我更倾向于把它叫做脚本执行策略).我们可以在不同的应用场景中设置不同的策略来防止恶意脚本 ...
- 使用LR编写windows sockets协议xml报文格式脚本实战
以下是测试脚本Demo: #include "lrs.h" Action() { char * resultCode;//结果代码 char * time; //系统时间 char ...
- 简单易用的安装文件制作工具NSIS的使用demo示例
安装文件制作工具NSIS 使用总结 在给客户开发客户端软件时,为避免技术人员亲自上门安装带来额外的成本损耗,通常我们都会自作一个安装包,以确保我们开发的程序的相关依赖资源.环境在客户端运行前能自动 ...
随机推荐
- serdes集成流程前端
serdes是 IP中间比较大的复杂的一个.集成前需要进行准备工作,千万不要一上来就写代码,这样非容易越写越差,先要做好规划,与合入计划. 1.收到IP材料后,第一时间检查内容都有哪些资料可以学习,使 ...
- 使用Python合并多个Excel文件
合并Excel可以将多个文件中的数据合并到一个文件中,这样可以帮助我们更好地汇总和管理数据.日常工作中,合并Excel主要有以下两种需求: 将多个Excel文件合并为一个文件 将多个Excel工作表合 ...
- 神奇的 SQL ,高级处理之 Window Functions → 打破我们的局限!
开心一刻 今天儿子跟老婆聊天 儿子:妈妈,我为什么没有两个爸爸呀 老婆:每个人都只有一个爸爸呀,你看谁有两个爸爸了 儿子一脸真诚的看着老婆:那你为什么就有两个爸爸呢 老婆一脸疑惑的望向儿子:我哪有两个 ...
- 一文讲透消息队列RocketMQ实现消费幂等
这篇文章,我们聊聊消息队列中非常重要的最佳实践之一:消费幂等. 1 基础概念 消费幂等是指:当出现 RocketMQ 消费者对某条消息重复消费的情况时,重复消费的结果与消费一次的结果是相同的,并且多次 ...
- python、numpy计算不同文档下的词的TF-IDF值以及进行文档相似度匹配(实战)
TF-IDF 计算公式(一个词的 tf-idf 值在不同文档,它的值也不同): 1.根据已有的原始数据,只展示了前5片文档,content是文档内容,s_words是通过jieba分词将文档划分成了若 ...
- bash shell笔记整理——外部命令和内部命令区别
linux命令的类别: 外部命令 内部命令 什么是内部命令 bash shell程序内部自带的命令. 什么是外部命令 不是bash shell内建命令,bash会根据用户给定的命令从PATH环境变量中 ...
- SQL优化三步曲
有一天开发同学反馈线上业务库中有一条SQL执行很满,每次几乎要跑1分钟才结束,希望我们帮忙优化一下,具体SQL如下: SQL优化第一步 - 查看执行计划 对于一个SQL的优化,我们的第一步也是最重要的 ...
- 终于卷完了!MySQL 打怪升级进阶成神之路(2023 最新版)!
从第一篇文章开始,我们逐步详细介绍了 MySQL 数据库的基础知识,如:数据类型.存储引擎.性能优化(软.硬及sql语句),MySQL 数据库的高可用架构的部分,如:主从同步.读写分离的原理与实践.跨 ...
- 《Span-Based Joint Entity and Relation Extraction with Transformer Pre-Training》阅读笔记
代码 原文地址 预备知识: 1.什么是束搜索算法(beam search)? beam search是一种用于许多自然语言处理和语音识别模型的算法,作为最终决策层,用于在给定目标变量(如最大概 ...
- 新版的Django中的path不能使用正则表达式
新版的path 虽然 取代了 之前的url,但是在写路由的时候不能在路由中直接写正则表达式,不然会找不到页面. 解决方法使用 re_path from django.urls import re_pa ...