概述

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的更多相关文章

  1. paddlespeech asr 使用教程

    目录 安装 paddle框架安装 软件源安装 源码安装 快速使用 下载测试使用的音频 非流式命令行接口(CLI) 非流式Server服务 流式Server服务 指令详解 打印paddlespeech_ ...

  2. Appium之开发计算器自动化测试脚本Demo

    1.依赖包 <!-- https://mvnrepository.com/artifact/io.appium/java-client --> <dependency> < ...

  3. oozie调度hive脚本demo

    1. 环境配置 2. 脚本配置 3. 执行job 4. 查看结果 待发布 ..

  4. 基于python3.7的一个闯越自动签到脚本--demo版

    望指正demo的定位,有时候会抽风无法接受我的定位信息 #! /usr/bin/python3 # -*- coding:UTF- -*- # time : // : # file : chuangy ...

  5. 验证销售部门的数据查看权限-脚本demo

    1 # coding:utf-8 2 ''' 3 @file: run_old.py 4 @author: jingsheng hong 5 @ide: PyCharm 6 @createTime: ...

  6. appium+Python真机运行测试demo的方法

    appium+Python真机运行测试demo的方法 一,    打开手机的USB调试模式 二,    连接手机到电脑 将手机用数据线连接到电脑,并授权USB调试模式.查看连接的效果,在cmd下运行命 ...

  7. 将表数据生成Insert脚本

    set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgo-- =============================================-- Author ...

  8. PowerShell 脚本执行策略

    为防止恶意脚本的执行,PowerShell 中设计了一个叫做执行策略(Execution Policy)的东西(我更倾向于把它叫做脚本执行策略).我们可以在不同的应用场景中设置不同的策略来防止恶意脚本 ...

  9. 使用LR编写windows sockets协议xml报文格式脚本实战

    以下是测试脚本Demo: #include "lrs.h" Action() { char * resultCode;//结果代码 char * time; //系统时间 char ...

  10. 简单易用的安装文件制作工具NSIS的使用demo示例

    安装文件制作工具NSIS 使用总结   在给客户开发客户端软件时,为避免技术人员亲自上门安装带来额外的成本损耗,通常我们都会自作一个安装包,以确保我们开发的程序的相关依赖资源.环境在客户端运行前能自动 ...

随机推荐

  1. serdes 常见并口位宽

    serdes主要完成串并转换功能.常见的并口位宽如下: GE/10/25GE/32GE        10/20/40/16/32位 50GE                              ...

  2. Socket.D 网络应用协议,v2.1.6 发布

    有用户说,"Socket.D 之于 Socket,尤如 Vue 之于 Js.Mvc 之于 Http" 与其它协议的简单对比 对比项目 socket.d http websocket ...

  3. Winform RichTextBox 控件文本内容自动滚动到最后一行

    RichTextBox 控件文本内容始终显示追加的最新内容,也就是自动滚动到控件文本框的最后一行. 有两种方法: HideSelection设置为false: // RichTextBox1.Text ...

  4. 【matlab混沌理论】1.2.洛伦兹吸引子

    ​Lorenz洛伦兹吸引子定义洛伦兹函数组后,通过ode45函数求解此微分方程方程. input: % Lorenz函数的洛伦兹吸引子 % 2.定义模型参数 sigma = 10; beta = 8/ ...

  5. 【.NET】控制台应用程序的各种交互玩法

    老周是一个不喜欢做界面的码农,所以很多时候能用控制台交互就用控制台交互,既方便又占资源少.有大伙伴可能会说,控制台全靠打字,不好交互.那不一定的,像一些选项类的交互,可以用键盘按键(如方向键),可比用 ...

  6. 2024年 Kubernetes 四大趋势预测

    Kubernetes 在生产环境中的复杂性已经成为常态,在2023年这个平台工程盛行的时代,容器管理的最大亮点可能在于其灵活性,然而在运维政策和治理等方面仍然存在诸多挑战.Kubernetes 最大的 ...

  7. 华企盾DSC备用服务器无法启动,日志显示“主服务器停机超过十天”

    ​ 出现该问题有三种情况: 1.主服务器未启动或授权到期: 2.主服务器申请的在线授权且ERP上存在到期的相同序列号: 3.备用服务器的数据库与主服务器连的不是同一个(检查IP和端口以及数据库名).

  8. 2023年最后一个工作日,当 hr总监找上我协商赔偿

    今天是2023年最后一个工作日,hr 总监找上我协商赔偿一事,忆往昔三年前,公司刚融资1个亿,意气风发,博主入职即为公司巅峰,高级开发岗,14薪,各种福利,加班另算加班费,业务主要服务于众多500强集 ...

  9. 一文了解Vprix容器流媒体平台和传统云桌面的区别、优劣势

    在当今数字化时代,随着云计算和远程办公的兴起,云桌面项目成为了提升工作效率和灵活性的重要工具.云桌面项目通过将用户的桌面环境和应用程序虚拟化,为用户提供了随时随地访问个人工作环境的便利.本文将介绍Vp ...

  10. 开发篇1:使用原生api和Langchain调用大模型

    对大模型的调用通常有以下几种方式:方式一.大模型厂商都会定义http风格的请求接口,在代码中可以直接发起http请求调用:方式二.在开发环境中使用大模型厂商提供的api:方式三.使用开发框架Langc ...