技术标签: 语音信号处理 语音增强 分段信噪比 PESQ 语音评价指标 STOI
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
@Time : 2020/9/13 16:53
@Author : kingback
@Site :
@File : SEPM.py
@Software: PyCharm
'''
'''
the install order is :
因为一些函数包需要一些依赖,所以建议大家按照如下步骤安装操作
0. All the package I use the commond "python setup.py install" to install to our machine.
Maybe we also need to install other packages like : cython ,numba ,scipy ,matplotlib ,numpy ...
0.说明,以下所有的安装包最好都再对应的github链接下载其源码,然后cmd进入到其对应的文件见,执行python setup.py install命令来进行安装
1. install the gammatone from : https://github.com/detly/gammatone
1. 第一步,先安装这个包,下载地址如上,下载好后进入文件夹执行命令python setup.py install
2.install the SRMRpy from : https://github.com/jfsantos/SRMRpy
2.这是需要安装的第二个包,因为这些包都是有依赖关系的,所以建议大家还是按照这个顺序来
3.install the python-pesq from : https://github.com/vBaiCai/python-pesq
3.这是第三个包
4.install the pystoi from : https://github.com/mpariente/pystoi
4.这是第四个
5.install the pyseqm from : https://github.com/schmiph2/pysepm
5.这是第五个
'''
如果大家链接github速度较慢,可以访问那五个安装包,提取码:r809
环境搭建的话,博主是使用conda新创了个python3.6的虚拟环境,然后再搭建的这个语音质量指标环境,以下是搭建过程及步骤:
1.创建新环境 conda create -n tp python=3.6
2.激活环境 activate tp
3.安装必备包(因为下边要安装的包需要这些依赖,如果使用pip源的话就很慢,所以在这里提前下载下来,这三个包必须提前安装哈)
pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install scipy -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install numba -i https://pypi.tuna.tsinghua.edu.cn/simple
4. 进入到gammatone_master里边执行python setup.py install命令
5. 安装成功,如下图所示
6. 紧接着同样的步骤安装SRMRpy,记得切换到tp环境哦
然后执行python setup.py install进行安装,出现以下界面就是安装成功了
7.接下来安装pesq,和上边的步骤一样,在对应的文件夹下进入cmd命令行,然后切换到tp虚拟环境,执行命令python setup.py install
8.和上边的操作一样,安装第四个包pystoi
9.步骤同上,安装第五个包pysepm
因为新环境并没有soundfile包(用于读取语音文件)和tqdm包(用于显示进度),所以想要以下代码,还需要安装这俩包,执行以下命令
pip install soundfile tqdm
以下就是安装成功的结果啦
都安装完以后,就可以测试语音的质量指标啦,以下就是全部的代码:
import pysepm
import os
import numpy as np
import soundfile as sf
from tqdm import tqdm
clean_wavs = 'clean_testset_wav_16k/'#这个路径,大家根据自己的需求进行修改
denoised_wavs = 'cleaned_testset_wav_16k_48700/'#同理进行修改
def file_name(file_dir):
L = []
for root, dirs, files in os.walk(file_dir):
for file in files:
if os.path.splitext(file)[1] == '.wav':
L.append(os.path.join(root, file))
return L
# get wav_lists
clean_lists = file_name(clean_wavs)
denoised_lists = file_name(denoised_wavs)
# Package files
zipped = zip(clean_lists, denoised_lists)
scores = []
CSIGs = []
CBAKs = []
COVLs = []
for (clean_wav, denoised_wav) in tqdm(zipped, 'the progressing ...'):
# Gain speech parameters
ref, sr0 = sf.read(clean_wav)
deg, sr1 = sf.read(denoised_wav)
'''
# Method 1: SNRseg (分段信噪比)
# from pysepm Call SNRseg to calculate its metrics
# in this case we can choose our frame length =0.03*1000=30 ms , and the overlap =30 ms *0.75 =22.5 ms
# 得分越高,质量越好
'''
# score = pysepm.SNRseg(ref, deg, sr0)
'''
# Method 2: llr (对数似然比测度)
#
# 得分越高,质量越好
'''
# score = pysepm.llr(ref, deg, sr0)
'''
# Method 3: WSS (加权谱倾斜测度)
#
# 得分越低,质量越好
'''
score = pysepm.wss(ref, deg, sr0)
'''
# Method 4: STOI (可短时客观可懂)
#
# the score from 0-1 . The higher the score, the better the performance.
#得分范围0~1,得分越高,质量越好
'''
# score = pysepm.stoi(ref, deg, sr0)
'''
# Method 5: PESQ
# when I try this commond , I faced some troubles , so finally I gave up this commond,
# use the PESQ.py to instead
得分范围从 -0.5~ 4.5,得分越高,效果越好
'''
NaN,score = pysepm.pesq(ref,deg,sr0)
'''
# Method 6: CD (Cepstrum Distance)
#
# 数值越高,得分越高.
'''
# score = pysepm.cepstrum_distance(ref, deg, sr0)
'''
# Method 7: LSD (对数谱距离)
# This method I use the LSD.py to calculate the distance
# 数值越小,得分越高
'''
'''
Method 1 - 7 use this score to print
'''
# score append to scores
scores.append(score)
'''
# Method 8: Composite
# In this method , It comes some errors, if you want to solve the error , see the step 8 in this file.
# CSIG , CBAK , COVL all from 1 - 5 , The higher the score, the better the performance.
'''
# CSIG,CBAK,COVL = pysepm.composite(ref, deg, sr0)
# CSIGs.append(CSIG)
# CBAKs.append(CBAK)
# COVLs.append(COVL)
# print(scores)
print('The average SegSNR evaluation is : ', sum(scores) / len(scores))
# calculate the standard deviation & variance of the scores
print('The standard deviation is : ', np.std(scores))
print('The variance is : ', np.var(scores))
# print(CSIGs,CBAKs,COVLs)
# print('The average CSIG evaluation is : ', sum(CSIGs) / len(CSIGs))
# print('The average CBAK evaluation is : ', sum(CBAKs) / len(CBAKs))
# print('The average COVL evaluation is : ', sum(COVLs) / len(COVLs))
6. if you have finished the last step ,don't forget to change the next step's setup.py .
This is done so that you do not have to repeatedly download the installed files.
And there's also the possibility of an error.
如果你在程序运行过程中出现以下问题,可以参考以下解决方案。
7. 如果你的代码在执行过程中遇到以下问题,可以参照此教程,
"
File "/home/king/anaconda3/envs/tf_gpu/lib/python3.6/site-packages/pysepm-0.1-py3.6.egg/pysepm/__init__.py", line 4, in <module>
File "/home/king/anaconda3/envs/tf_gpu/lib/python3.6/site-packages/pysepm-0.1-py3.6.egg/pysepm/qualityMeasures.py", line 4, in <module>
ModuleNotFoundError: No module named 'pesq'
"
找到你的环境中的这个pysepm/qualityMeasures.py文件,当然路径肯定和我这不一样哈
you can go to your file path "/home/king/anaconda3/envs/tf_gpu/lib/python3.6/site-packages/pysepm-0.1-py3.6.egg/pysepm/qualityMeasures.py"
在源码中找到如下命令:
#import pesq as pypesq # https://github.com/ludlows/python-pesq
替换为 :
import pypesq
9. if you run the method pesq & Composite , it may be come some errors because we haven't introduced PESQ packages properly yet.
10.如果你在测量语音的pesq指标,和Composite 指标(即CBark,CSIG,COVL) ,如果出现问题,建议使用如下解决方案
打开以下文件
you can go to your file path "/home/king/anaconda3/envs/tf_gpu/lib/python3.6/site-packages/pysepm-0.1-py3.6.egg/pysepm/qualityMeasures.py"
(1) 操作1 #在文件开头添加以下命令
"from pypesq import pesq as pq"
(2).操作2 ,替换347-359行的pesq函数
"
def pesq(clean_speech, processed_speech, fs):
if fs == 8000:
mos_lqo = pq(clean_speech,processed_speech, fs)
pesq_mos = 46607/14945 - (2000*np.log(1/(mos_lqo/4 - 999/4000) - 1))/2989#0.999 + ( 4.999-0.999 ) / ( 1+np.exp(-1.4945*pesq_mos+4.6607) )
elif fs == 16000:
mos_lqo = pq(clean_speech,processed_speech, fs)
pesq_mos = np.NaN
else:
raise ValueError('fs must be either 8 kHz or 16 kHz')
return pesq_mos,mos_lqo
"
(3).保存并且退出
博主在近期重新搞了搞这个,其实如果重新搭建环境并且按照 第二部分和第三部分环境搭建的话是没有出现问题的,且经过博主本人再三检测,以上所有音频指标均可正常检测,如果大家在使用过程中出现错误,为方便大家,我将该conda虚拟环境传输到百度云网盘,以提供给大家使用,下载完成后,将tp环境放置到conda安装路径下的envs文件夹下,之后选择虚拟环境,就可以直接在这个虚拟环境上进行操作啦。百度云链接,提取码:ggek
本博客中用于检测的音频数据,我也一并上传至百度网盘,大家也可拿来进行测试数据集链接,提取码:ybjp
- https://github.com/schmiph2/pysepm/blob/master/examples/examplesForCalculatingMeasures.ipynb (How to use the packages of SEPM)
- https://zhuanlan.zhihu.com/p/190146707 (音频质量客观评价指标)
时间 | 操作 |
---|---|
2021年4月21日 | 首发 |
2022年5月8日 | 重新编辑博客并上传网盘 |
文章浏览阅读1k次。通过使用ajax方法跨域请求是浏览器所不允许的,浏览器出于安全考虑是禁止的。警告信息如下:不过jQuery对跨域问题也有解决方案,使用jsonp的方式解决,方法如下:$.ajax({ async:false, url: 'http://www.mysite.com/demo.do', // 跨域URL ty..._nginx不停的xhr
文章浏览阅读2k次。关于在 Oracle 中配置 extproc 以访问 ST_Geometry,也就是我们所说的 使用空间SQL 的方法,官方文档链接如下。http://desktop.arcgis.com/zh-cn/arcmap/latest/manage-data/gdbs-in-oracle/configure-oracle-extproc.htm其实简单总结一下,主要就分为以下几个步骤。..._extproc
文章浏览阅读1.5w次。linux下没有上面的两个函数,需要使用函数 mbstowcs和wcstombsmbstowcs将多字节编码转换为宽字节编码wcstombs将宽字节编码转换为多字节编码这两个函数,转换过程中受到系统编码类型的影响,需要通过设置来设定转换前和转换后的编码类型。通过函数setlocale进行系统编码的设置。linux下输入命名locale -a查看系统支持的编码_linux c++ gbk->utf8
文章浏览阅读750次。今天准备从生产库向测试库进行数据导入,结果在imp导入的时候遇到“ IMP-00009:导出文件异常结束” 错误,google一下,发现可能有如下原因导致imp的数据太大,没有写buffer和commit两个数据库字符集不同从低版本exp的dmp文件,向高版本imp导出的dmp文件出错传输dmp文件时,文件损坏解决办法:imp时指定..._imp-00009导出文件异常结束
文章浏览阅读143次。当下是一个大数据的时代,各个行业都离不开数据的支持。因此,网络爬虫就应运而生。网络爬虫当下最为火热的是Python,Python开发爬虫相对简单,而且功能库相当完善,力压众多开发语言。本次教程我们爬取前程无忧的招聘信息来分析Python程序员需要掌握那些编程技术。首先在谷歌浏览器打开前程无忧的首页,按F12打开浏览器的开发者工具。浏览器开发者工具是用于捕捉网站的请求信息,通过分析请求信息可以了解请..._初级python程序员能力要求
文章浏览阅读7.6k次,点赞2次,收藏6次。@Service标注的bean,类名:ABDemoService查看源码后发现,原来是经过一个特殊处理:当类的名字是以两个或以上的大写字母开头的话,bean的名字会与类名保持一致public class AnnotationBeanNameGenerator implements BeanNameGenerator { private static final String C..._@service beanname
文章浏览阅读6.9w次,点赞73次,收藏463次。1.前序创建#include<stdio.h>#include<string.h>#include<stdlib.h>#include<malloc.h>#include<iostream>#include<stack>#include<queue>using namespace std;typed_二叉树的建立
文章浏览阅读7.1k次。在Asp.net上使用Excel导出功能,如果文件名出现中文,便会以乱码视之。 解决方法: fileName = HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8);_asp.net utf8 导出中文字符乱码
文章浏览阅读2.1k次,点赞4次,收藏23次。第一次实验 词法分析实验报告设计思想词法分析的主要任务是根据文法的词汇表以及对应约定的编码进行一定的识别,找出文件中所有的合法的单词,并给出一定的信息作为最后的结果,用于后续语法分析程序的使用;本实验针对 PL/0 语言 的文法、词汇表编写一个词法分析程序,对于每个单词根据词汇表输出: (单词种类, 单词的值) 二元对。词汇表:种别编码单词符号助记符0beginb..._对pl/0作以下修改扩充。增加单词
文章浏览阅读773次。我在使用adb.exe时遇到了麻烦.我想使用与bash相同的adb.exe shell提示符,所以我决定更改默认的bash二进制文件(当然二进制文件是交叉编译的,一切都很完美)更改bash二进制文件遵循以下顺序> adb remount> adb push bash / system / bin /> adb shell> cd / system / bin> chm..._adb shell mv 权限
文章浏览阅读6.8k次,点赞12次,收藏125次。1. 单目相机标定引言相机标定已经研究多年,标定的算法可以分为基于摄影测量的标定和自标定。其中,应用最为广泛的还是张正友标定法。这是一种简单灵活、高鲁棒性、低成本的相机标定算法。仅需要一台相机和一块平面标定板构建相机标定系统,在标定过程中,相机拍摄多个角度下(至少两个角度,推荐10~20个角度)的标定板图像(相机和标定板都可以移动),即可对相机的内外参数进行标定。下面介绍张氏标定法(以下也这么称呼)的原理。原理相机模型和单应矩阵相机标定,就是对相机的内外参数进行计算的过程,从而得到物体到图像的投影_相机-投影仪标定
文章浏览阅读2.2k次。文章目录Wayland 架构Wayland 渲染Wayland的 硬件支持简 述: 翻译一篇关于和 wayland 有关的技术文章, 其英文标题为Wayland Architecture .Wayland 架构若是想要更好的理解 Wayland 架构及其与 X (X11 or X Window System) 结构;一种很好的方法是将事件从输入设备就开始跟踪, 查看期间所有的屏幕上出现的变化。这就是我们现在对 X 的理解。 内核是从一个输入设备中获取一个事件,并通过 evdev 输入_wayland