python 录音vad_语音活性检测器py-webrtcvad安装使用
谷歌为WebRTC项目开发的VAD是目前最优秀、最先进和免费的产品之一。webrtcvad是WebRTC语音活动检测器(VAD)的python接口。兼容python2和python3。功能是将一段音频数据分为静音与非静音。它对于电话和语音识别很有用。1、安装pipyum -y install epel-releaseyum -y install python-pip2、安装webrtcvadyum
谷歌为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 \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
python 使用 setup.py 方式安装及包的卸载
安装: 可通过 --home 或 --prefix 指定安装目录 --prefix=xx/xxx 选择安装目录 --record files.txt 记录所有安装文件的路径 ...
python 利用 setup.py 手动安装第三方类库
python 利用 setup.py 手动安装第三方类库 由于我在mac使用时,装了python3,默认有python2的环境,使用 pip 安装第三方类库时,老是安装到 python2的环境上: 在 ...
python 利用 setup.py 手动安装django_chartit
手动安装django_chartit库 1 下载压缩包 2 解压到python安装目录下,文件夹名为django_chartit,并检查文件夹下是否有setup.py文件 3 在cmd中进入djang ...
对于python setup.py install安装的包如何卸载
easy_install 安装 卸载命令 easy_install -m package-name setup.py安装 帮助你纪录安装细节方便你卸载 python setup.py install ...
easygui.py的安装和下载地址
easygui下载地址:http://nchc.dl.sourceforge.net/project/easygui/0.97/easygui-0.97.zip 安装:解压后将easygui.py拷贝 ...
简单使用setup.py来安装Python项目
最近做个一个项目需要用到setup.py 这个构建工具来进行项目的便捷安装,把搜集到的一些资料加上个人理解整理成文章,如有错误的地方请各位大佬及时指出,小弟马上修改,下面正式进入setup.py的描述 ...
ez_setup.py(安装python下setuptools用)
#!python"""Bootstrap setuptools installation If you want to use setuptools in your pa ...
【py】安装ipython-notebook
os:ubunutu(debian)-based linux 分两步: 安装ipython及其依赖包 sudo apt-get install ipython-notebook 安装可选的附加工具 ...
Linux 问题 卸载setup.py方式安装的python包
python ./setup.py install --record install.txt cat install.txt | xargs rm -rf
随机推荐
IIS6(Win2003) 使用.net 4.0 后,默认文档失效解决方案。
IIS6(Win2003) 使用.net framework 4.0 后,默认文档失效解决方案. 用.net framework 4.0 开发的WEB项目,但放到iis6 中无法使用默认文档,状况如下 ...
关于Asp.Net MVC 中 UpdateModel 的未能更新***模型的 解决方案!
解决方案参考: http://blog.csdn.net/hudaijun/article/details/7293129 想法: 其实,不用UpdateModel,虽然笨些,但不会出什么古怪问题.当 ...
Threading in C#
http://www.albahari.com/threading/ PART 1: GETTING STARTED Introduction and Concepts C# supports par ...
hdu 1867 A + B for you again
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1867 A + B for you again Description Generally speaki ...
【CF】174 Div.1 B Cow Program
思路是树形DP+状态压缩.其实仅有2个状态,奇数次来到x或者偶数次来到x.(因为对x的更新不同).同时开辟visit数组,解决环.注意,一旦遇到环结果就是-1.DP数组存放第奇数/偶数次来到x时,对y ...
(转)eclipse 启动参数介绍(如添加插件时,如果不显示,则使用eclipse -clean启动)
本文转载自:http://hi.baidu.com/dd_taiyangxue/blog/item/08950f3991b4e8c9d46225c8.html 其实,Eclipse是一个可以进行非常灵 ...
应用负载均衡之LVS(三):使用ipvsadm以及详细分析VS/DR模式
*/ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hl ...
Kubernetes-基于flannel的集群网络
1.Docker网络模式 在讨论Kubernetes网络之前,让我们先来看一下Docker网络.Docker采用插件化的网络模式,默认提供bridge.host.none.overlay.maclan ...
redis(三)
string string是redis最基本的类型 最大能存储512MB数据 string类型是二进制安全的,即可以为任何数据,比如数字.图片.序列化对象等 命令 设置 设置键值 set key va ...
【ASP.NET Core】EF Core - “影子属性”
有朋友说老周近来博客更新较慢,确实有些慢,因为有些 bug 要研究,另外就是老周把部分内容转到直播上面,所以写博客的内容减少了一点. 老周觉得,视频直播可能会好一些,虽然我的水平一般,不过直播时,老周 ...
更多推荐
所有评论(0)