基于PaddleSpeech搭建个人语音听写服务

系统维
• 阅读 1225

.需求分析

亲们,你们要写会议纪要嘛?
亲们,你们要写会议纪要嘛?
亲们,你们要写会议纪要嘛?

当您面对成吨的会议录音,着急写会议纪要而不得不愚公移山、人海战术?听的头晕眼花,听的漏洞百出,听的怀疑人生,那么你是否想到了自动听写服务?
想想也是,百度一看,好家伙,收费不菲啊!请看下图

基于PaddleSpeech搭建个人语音听写服务

基于PaddleSpeech搭建个人语音听写服务

2.需求再分析
亲密,能花钱解决的都不是事,刚刚看到听写服务,很贵的,大致1400大洋,还是打折完毕的,而且还是云服务形式的,那么对于某些会议,比如保密会议,需要离线的,那么完全办不到,该怎么办呢?
下面就有请我们的PaddleSpeech出场来解决问题。
3.解决思路
【超简单】之基于PaddleSpeech搭建个人语音听写服务,顾名思义,是通过PaddleSpeech来搭建语音听写服务的,主要思路如下。

1.录音长度切分
2.录音听写
3.录音文本加标点

二、环境搭建
1.PaddleSpeech简介
PaddleSpeech 是基于飞桨 PaddlePaddle 的语音方向的开源模型库,用于语音和音频中的各种关键任务的开发,包含大量基于深度学习前沿和有影响力的模型,一些典型的应用如下:

语音识别
语音翻译
语音合成

2.PaddleSpeech安装
pip install paddlespeech
复制代码
2.1相关依赖

gcc >= 4.8.5
paddlepaddle >= 2.3.1
python >= 3.7
linux(推荐), mac, windows

2.2 win安装注意事项

1.win必须安装 Microsoft C++ 生成工具 - Visual Studio
visualstudio.microsoft.com/zh-hans/vis… 工具,原因是 安装非纯 Python 包或编译 Cython 或 Pyrex 文件。

2.参考: WindowsCompilers - Python Wiki
wiki.python.org/moin/Window…

!pip install paddlespeech >log.log
复制代码
2.3 快速试用
!wget -c https://paddlespeech.bj.bcebo...
复制代码
--2022-07-27 00:31:57-- https://paddlespeech.bj.bcebo...
Resolving paddlespeech.bj.bcebos.com (paddlespeech.bj.bcebos.com)... 182.61.200.195, 182.61.200.229, 2409:8c04:1001:1002:0:ff:b001:368a
Connecting to paddlespeech.bj.bcebos.com (paddlespeech.bj.bcebos.com)|182.61.200.195|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 159942 (156K) [audio/wav]
Saving to: ‘zh.wav’

zh.wav 100%[===================>] 156.19K --.-KB/s in 0.03s

2022-07-27 00:31:57 (5.52 MB/s) - ‘zh.wav’ saved [159942/159942]
复制代码
2.3.1 API调用
from paddlespeech.cli.asr.infer import ASRExecutor

asr = ASRExecutor()
result = asr(audio_file="zh.wav")
复制代码
[2022-07-27 00:33:02,175] [ INFO] - checking the audio file format......
复制代码
print(result)
复制代码
我认为跑步最重要的就是给我带来了身体健康
复制代码
2.3.2 命令行调用
!paddlespeech asr --lang zh --input zh.wav
复制代码
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/nltk/decorators.py:68: DeprecationWarning: formatargspec is deprecated since Python 3.5. Use signature and the Signature object directly
regargs, varargs, varkwargs, defaults, formatvalue=lambda value: ""
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/nltk/lm/counter.py:15: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Sequence, defaultdict
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/nltk/lm/vocabulary.py:13: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Counter, Iterable
[nltk_data] Downloading package averaged_perceptron_tagger to
[nltk_data] /home/aistudio/nltk_data...
[nltk_data] Unzipping taggers/averaged_perceptron_tagger.zip.
[nltk_data] Downloading package cmudict to /home/aistudio/nltk_data...
[nltk_data] Unzipping corpora/cmudict.zip.
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/__init__.py:107: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import MutableMapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/rcsetup.py:20: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Iterable, Mapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/colors.py:53: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Sized
W0727 00:38:55.935500 2181 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0727 00:38:55.940197 2181 gpu_resources.cc:91] device: 0, cuDNN Version: 7.6.
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/h5py/__init__.py:36: DeprecationWarning: np.typeDict is a deprecated alias for np.sctypeDict.
from ._conv import register_converters as _register_converters
我认为跑步最重要的就是给我带来了身体健康
复制代码
会自动下载一堆东西有点慢,可以不用这个。
[nltk_data] Downloading package averaged_perceptron_tagger to
[nltk_data] /home/aistudio/nltk_data...
[nltk_data] Unzipping taggers/averaged_perceptron_tagger.zip.
[nltk_data] Downloading package cmudict to /home/aistudio/nltk_data...
复制代码
2.3.3 常见错误
如遇到以下错误
[2022-07-26 21:13:28,589] [ INFO] - checking the audio file format......
[2022-07-26 21:13:28,594] [ ERROR] - Please input audio file less then 50 seconds.
复制代码
报错很明显,提示一个是音频格式问题,一个是小于50s问题,如果遇到这个问题后面解决。

1.音频必须为wav格式

2.音频大小必须小于50s

音频格式为wav格式,这个可通过录音笔设置(一般默认),或python代码转换,或者格式工厂进行转换。
3.音频切分
此处使用auditok库
!pip install auditok
复制代码
Looking in indexes: https://pypi.tuna.tsinghua.ed...
Collecting auditok
Downloading https://pypi.tuna.tsinghua.ed... (1.5 MB)

 l     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0.0/1.5 MB ? eta -:--:--━━━━━━━━━━╸━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0.4/1.5 MB 14.2 MB/s eta 0:00:01━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸━━━━━━ 1.3/1.5 MB 19.7 MB/s eta 0:00:01━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.5/1.5 MB 15.4 MB/s eta 0:00:00

[?25hInstalling collected packages: auditok
Successfully installed auditok-0.2.0

[notice] A new release of pip available: 22.1.2 -> 22.2
[notice] To update, run: pip install --upgrade pip
复制代码
三、音频切分
切分原因上面交代过,因为PaddleSpeech识别最长语音为50s,故需要切分,这里直接调用好了。
from paddlespeech.cli.asr.infer import ASRExecutor
import csv
import moviepy.editor as mp
import auditok
import os
import paddle
from paddlespeech.cli import ASRExecutor, TextExecutor
import soundfile
import librosa
import warnings

warnings.filterwarnings('ignore')
复制代码

引入auditok库

import auditok

输入类别为audio

def qiefen(path, ty='audio', mmin_dur=1, mmax_dur=100000, mmax_silence=1, menergy_threshold=55):

audio_file = path
audio, audio_sample_rate = soundfile.read(
    audio_file, dtype="int16", always_2d=True)

audio_regions = auditok.split(
    audio_file,
    min_dur=mmin_dur,  # minimum duration of a valid audio event in seconds
    max_dur=mmax_dur,  # maximum duration of an event
    # maximum duration of tolerated continuous silence within an event
    max_silence=mmax_silence,
    energy_threshold=menergy_threshold  # threshold of detection
)

for i, r in enumerate(audio_regions):
    # Regions returned by `split` have 'start' and 'end' metadata fields
    print(
        "Region {i}: {r.meta.start:.3f}s -- {r.meta.end:.3f}s".format(i=i, r=r))

    epath = ''
    file_pre = str(epath.join(audio_file.split('.')[0].split('/')[-1]))

    mk = 'change'
    if (os.path.exists(mk) == False):
        os.mkdir(mk)
    if (os.path.exists(mk + '/' + ty) == False):
        os.mkdir(mk + '/' + ty)
    if (os.path.exists(mk + '/' + ty + '/' + file_pre) == False):
        os.mkdir(mk + '/' + ty + '/' + file_pre)
    num = i
    # 为了取前三位数字排序
    s = '000000' + str(num)

    file_save = mk + '/' + ty + '/' + file_pre + '/' + \
                s[-3:] + '-' + '{meta.start:.3f}-{meta.end:.3f}' + '.wav'
    filename = r.save(file_save)
    print("region saved as: {}".format(filename))
return mk + '/' + ty + '/' + file_pre

点赞
收藏
评论区
推荐文章
Wesley13 Wesley13
3年前
sql2008 r2 数据库 复制操作 代理作业失败的相关操作
前言:对于实在没有办法而又不得不使用sqlserver的亲们真是一路走来各种的辛酸呀!!!给各位亲们一个大大的赞,多的不说,直接步入正题解决问题。解决的方法:1.首先找到自己电脑的sqlserver配置管理器(win8自己在应用程序里面找到对应),然后点击打开。!(http://static.oschina.net/uploads/im
Wesley13 Wesley13
3年前
Unity使用TUIO协议接入雷达
本篇文章不介绍Unity、TUIO、雷达是什么以及有什么作用。刚接触TUIO的亲们,建议直接硬刚。至于刚接触Unity的亲,这边建议亲直接放弃治疗呢!手机贴吧版泡泡(7)(https://oscimg.oschina.net/oscnet/45c3785a9c031956bcd9ba6243d37201f3f.png"手机贴吧版泡泡(7)")(
Wesley13 Wesley13
3年前
JAVA读写文件
1/23@Description:写文件4@param@paramurl要写到服务器的路径5@param@paramfileName要写的文件名需要加前缀如.txt6@par
Stella981 Stella981
3年前
Crawler 不需要写代码的爬虫 不需要写正则的爬虫
CrawlerV1.0.01.代码还没有优化2.框架结构很简单3.部分功能需要你们给我需求,我后期添加测试(http://git.oschina.net/puguoan/Crawler操作指南)操作指南
Stella981 Stella981
3年前
Real World CTF 2020 DBaaSadge Writeup
刚打的RWCTF比赛,觉得题目是非常不错的,至少这个环境下,postgre是大部分Web选手的弱项,圈内也没有什么自动化测试工具,因此写这篇WP还是有必要的。由于大部分关键的技术点是我队里的亲姐们——鱼先做了,所以这里先贴一下人家的博客里的wp(鱼哥看到记得来拍我)https://f1sh.site/2021/01/11/realworld
Stella981 Stella981
3年前
NodeJs学习一NodeJs初识
一、前言按照惯例,先扯淡,就因为这货,现在才有了各大公司招聘的全栈工程师,正是因为它,让以前只会写前端的人也能写起后端服务器代码来了。所以呢,你招一个会NodeJs的前端,它都能把后端干了,一个人干了两个人的事,你说哪个公司不想要。但是我还是要同情一下前端的兄弟们,真是苦了你们了,以前你们只是写页面就完了,现在还得写后台,再加上各种前端框架,什么
Stella981 Stella981
3年前
OSChina 周四乱弹 —— 做出这题,分分钟当公务员
各位程序员们,我们又早上见了,你们知道对于一个起床困难户来说,要每天早起发乱弹是件多么痛苦的事情吗?你们要是谁有这样的床,麻烦告诉我一声,我高价收购@doge酱(http://my.oschina.net/nyaruko):这样的床哪里有得卖,急求!http://static.oschina.net/uploads/sp
Stella981 Stella981
3年前
Spring Cloud Alibaba 深度解密!
说说吧,程序猿们,你们还有谁不是“单身G”?想要“赢取”白富美,当上CTO,走上人生巅峰,不努力怎么可以?别人疯狂购物,你疯狂学习,努力30天,向阿里P6迈进!1000元,你能买到爱情还是买到高级手办?随便给女朋友买个礼物也不止这个钱吧~1000元你可以在“开课吧”学习30天直播课,掌握自学至少160天的60个精讲知识
Stella981 Stella981
3年前
OSChina 周四乱弹 —— 反手摸第二季来袭
各位程序员们,端午节要来了,公司有没有给你们发粽子吃呢?反正小小编只有一张购物卡,你们要不要帮我劝劝某人,让它买点粽子什么的犒劳一下?@无极限(http://my.oschina.net/stv5):端午节了哦!http://static.oschina.net/uploads/space/2015/0617/155657_H9Dx
Python进阶者 Python进阶者
1年前
python里有哪个好用的地址分析库嘛?
大家好,我是Python进阶者。一、前言前几天在Python铂金交流群【大写一个Y】问了一个Python数据处理的问题,问题如下:大佬们python里有哪个好用的地址分析库嘛?我现在用的是jionlp,会有一些错误,比如广东的“开平市长沙区”,会因为:长沙
幂简集成 幂简集成
1个月前
2025年最佳语音转文字API比较:一个报表31项指标近200条数据
语音转文字API是一种技术工具,能够将语音输入转换为可编辑的文本。此API广泛用于提高信息处理效率,支持语音指令识别及自动化文档生成。在实际应用中,它对于增强用户交互体验、提高生产力具有重要意义。主要使用场景包括客服系统中的自动记录、会议纪要生成、语言学习