谷歌为WebRTC项目开发的VAD是目前最优秀、最先进和免费的产品之一。webrtcvad是WebRTC语音活动检测器(VAD)的python接口。兼容python2和python3。功能是将一段音频数据分为静音与非静音。它对于电话和语音识别很有用。

1、安装pip

yum -y install epel-release
yum -y install python-pip

2、安装webrtcvad

yum -y install python-devel
pip install webrtcvad

3、webrtcvad测试脚本(test_webrtcvad.py

import collections
import contextlib
import sys
import wave import webrtcvad def read_wave(path):
with contextlib.closing(wave.open(path, 'rb')) as wf:
num_channels = wf.getnchannels()
assert num_channels == 1
sample_width = wf.getsampwidth()
assert sample_width == 2
sample_rate = wf.getframerate()
assert sample_rate in (8000, 16000, 32000)
pcm_data = wf.readframes(wf.getnframes())
return pcm_data, sample_rate def write_wave(path, audio, sample_rate):
with contextlib.closing(wave.open(path, 'wb')) as wf:
wf.setnchannels(1)
wf.setsampwidth(2)
wf.setframerate(sample_rate)
wf.writeframes(audio) class Frame(object):
def __init__(self, bytes, timestamp, duration):
self.bytes = bytes
self.timestamp = timestamp
self.duration = duration def frame_generator(frame_duration_ms, audio, sample_rate):
n = int(sample_rate * (frame_duration_ms / 1000.0) * 2)
offset = 0
timestamp = 0.0
duration = (float(n) / sample_rate) / 2.0
while offset + n < len(audio):
yield Frame(audio[offset:offset + n], timestamp, duration)
timestamp += duration
offset += n def vad_collector(sample_rate, frame_duration_ms,
padding_duration_ms, vad, frames):
num_padding_frames = int(padding_duration_ms / frame_duration_ms)
ring_buffer = collections.deque(maxlen=num_padding_frames)
triggered = False
voiced_frames = []
for frame in frames:
sys.stdout.write(
'' if vad.is_speech(frame.bytes, sample_rate) else '')
if not triggered:
ring_buffer.append(frame)
num_voiced = len([f for f in ring_buffer
if vad.is_speech(f.bytes, sample_rate)])
if num_voiced > 0.9 * ring_buffer.maxlen:
sys.stdout.write('+(%s)' % (ring_buffer[0].timestamp,))
triggered = True
voiced_frames.extend(ring_buffer)
ring_buffer.clear()
else:
voiced_frames.append(frame)
ring_buffer.append(frame)
num_unvoiced = len([f for f in ring_buffer
if not vad.is_speech(f.bytes, sample_rate)])
if num_unvoiced > 0.9 * ring_buffer.maxlen:
sys.stdout.write('-(%s)' % (frame.timestamp + frame.duration))
triggered = False
yield b''.join([f.bytes for f in voiced_frames])
ring_buffer.clear()
voiced_frames = []
if triggered:
sys.stdout.write('-(%s)' % (frame.timestamp + frame.duration))
sys.stdout.write('\n')
if voiced_frames:
yield b''.join([f.bytes for f in voiced_frames]) def main(args):
if len(args) != 2:
sys.stderr.write(
'Usage: example.py <aggressiveness> <path to wav file>\n')
sys.exit(1)
audio, sample_rate = read_wave(args[1])
vad = webrtcvad.Vad(int(args[0]))
frames = frame_generator(30, audio, sample_rate)
frames = list(frames)
segments = vad_collector(sample_rate, 30, 300, vad, frames)
for i, segment in enumerate(segments):
#path = 'chunk-%002d.wav' % (i,)
print('--end')
#write_wave(path, segment, sample_rate) if __name__ == '__main__':
main(sys.argv[1:])

4、运行命令(其中,第一个参数为敏感系数,取值0-3,越大表示越敏感,越激进,对细微的声音频段都可以识别出来;第二个参数为wav文件存放路径,目前仅支持8K,16K,32K的采样率,示例wav文件下载:73.wav 链接:https://pan.baidu.com/s/19YJB9u0zvCFGBLDRisK1KQ 密码:fgkf)

[root@host---- ~]# python test_webrtcvad.py  /home/.wav
+(2.1)-(3.36)--end
+(3.57)-(14.43)--end
+(15.3)-(16.14)--end
+(21.21)-(22.47)--end
+(22.68)-(24.6)--end
+(24.66)-(26.76)--end
+(26.76)-(27.81)--end
+(27.87)-(31.38)--end
+(31.38)-(32.91)--end
+(33.21)-(35.04)--end
+(35.73)-(41.43)--end
+(42.66)-(43.8)--end
+(43.95)-(51.03)--end
+(51.15)-(53.82)--end
+(53.82)-(59.85)--end
+(60.51)-(64.74)--end
+(65.46)-(67.26)--end
+(67.74)-(69.39)--end
+(69.42)-(74.55)--end
+(74.55)-(81.24)--end
+(81.51)-(87.66)--end
+(87.9)-(89.76)--end
+(91.08)-(92.04)--end
+(92.31)-(96.9)--end
+(97.23)-(102.27)--end
+(102.51)-(104.43)--end
+(104.43)-(105.9)--end
+(106.38)-(108.12)--end
+(108.69)-(110.16)--end
+(111.12)-(113.13)--end
+(113.13)-(114.87)--end
+(114.87)-(118.08)--end

语音活性检测器py-webrtcvad安装使用的更多相关文章

  1. python 使用 setup.py 方式安装及包的卸载

     安装:         可通过 --home 或 --prefix 指定安装目录 --prefix=xx/xxx    选择安装目录 --record files.txt   记录所有安装文件的路径 ...

  2. python 利用 setup.py 手动安装第三方类库

    python 利用 setup.py 手动安装第三方类库 由于我在mac使用时,装了python3,默认有python2的环境,使用 pip 安装第三方类库时,老是安装到 python2的环境上: 在 ...

  3. python 利用 setup.py 手动安装django_chartit

    手动安装django_chartit库 1 下载压缩包 2 解压到python安装目录下,文件夹名为django_chartit,并检查文件夹下是否有setup.py文件 3 在cmd中进入djang ...

  4. 对于python setup.py install安装的包如何卸载

    easy_install 安装 卸载命令 easy_install -m package-name setup.py安装 帮助你纪录安装细节方便你卸载 python setup.py install ...

  5. easygui.py的安装和下载地址

    easygui下载地址:http://nchc.dl.sourceforge.net/project/easygui/0.97/easygui-0.97.zip 安装:解压后将easygui.py拷贝 ...

  6. 简单使用setup.py来安装Python项目

    最近做个一个项目需要用到setup.py 这个构建工具来进行项目的便捷安装,把搜集到的一些资料加上个人理解整理成文章,如有错误的地方请各位大佬及时指出,小弟马上修改,下面正式进入setup.py的描述 ...

  7. ez_setup.py(安装python下setuptools用)

    #!python"""Bootstrap setuptools installation If you want to use setuptools in your pa ...

  8. 【py】安装ipython-notebook

    os:ubunutu(debian)-based linux 分两步: 安装ipython及其依赖包 sudo apt-get install ipython-notebook   安装可选的附加工具 ...

  9. Linux 问题 卸载setup.py方式安装的python包

    python ./setup.py install --record install.txt  cat install.txt | xargs rm -rf

随机推荐

  1. [LeetCode] Preimage Size of Factorial Zeroes Function 阶乘零的原像个数函数

    Let f(x) be the number of zeroes at the end of x!. (Recall that x! = 1 * 2 * 3 * ... * x, and by con ...

  2. JMeter参数化中存在逗号的解决方法

    在Jmeter中通过CSV Data Set Config进行参数化时,如果参数化数据中存在逗号(,)我们可以通过一下方式进行设置 如何存在中文乱码,可以设置file encoding:gb2312

  3. Android adb 串口调试

    adb (串口输入) echo 1 > /sys/class/remount/need_remount; mount -o rw,remount /system                  ...

  4. aspose 生成word 简单的文档操作

    package aspose.com.word; import com.aspose.words.Document;import com.aspose.words.DocumentBuilder; p ...

  5. Unity进阶----AssetBundle_01(2018/10/30)

    AssetBundle作用和定义 1).AssetBundle是一个压缩包包含模型.贴图.预制体.声音.甚至整个场景,可以在游戏运行的时候被加载: 2).AssetBundle自身保存着互相的依赖关系 ...

  6. CAJ转换成PDF在线方法是什么

    做学术性的朋友经常会需要将CAJ文件转换成PDF文件,毕竟CAJ文件只能在CAJ阅读器上显示,但是有很多转换软件并不能很好的完成转换,小编今天就为大家讲解一下CAJ转换成PDF在线方法是什么,大家要认 ...

  7. Cassandra数据模型

    Ⅰ.数据模型 1.1 Column 一组包含Name/Value Pair的数据叫Row,其中每一组Name/Value Pair叫Column Column是Cassandra最基本的数据结构,它是 ...

  8. Building gRPC Client iOS Swift Note Taking App

    gRPC is an universal remote procedure call framework developed by Google that has been gaining inter ...

  9. Python的基本语法2

    一.运算符 # 算术运算符, +, -, *, /, //, %, **, 注意//为整除 # 赋值运算符, =, +=, -=, *=, /=, //= ,%=, **= # 比较运算符, ==, ...

  10. AES加密的S盒和逆S盒的推导代码备份(C实现)

    摘取自https://www.cnblogs.com/Junbo20141201/p/9369860.html,感谢原作者的详细解读. #include <stdio.h> ][] = { ...