使用python从给定的音频文件中检测静音索引 [英] detecting the index of silence from a given audio file using python

查看:718
本文介绍了使用python从给定的音频文件中检测静音索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用numpy,struct等各种模块在python中处理音频文件.但是,我真的很难检测文件中的静音,因为静音在哪里.我遇到的方法之一是在音频信号上滑动固定时间间隔的窗口并记录平方元素的总和.我是python的新手,几乎不了解它,因此无法实现此方法.

I am trying to process an audio file in python using various modules like numpy, struct etc. But I am really having a hard time detecting silence in the file, as in where is the presence of silence. one on the methods I came across was to slide a window of fixed time interval over my audio signal and record the sum of squared elements. I am new to python and hardly aware of it thus unable to implement this method.

推荐答案

如果您对外部图书馆开放,一种快速的方法是使用 pydub .
pydub具有名为沉默的模块,该模块具有方法detect_silencedetect_nonsilent可能对您有用.
但是,唯一的鱼子酱是沉默至少需要半秒钟.

If you are open to outside libraries, one of the quick way to do is using pydub.
pydub has a module called silence that has methods detect_silence and detect_nonsilent that may be useful in your case.
However, the only caviar is that silence needs to be at-least half a second.

下面是我尝试使用音频文件的示例实现.但是,由于我的情况下的沉默时间不到半秒,因此只有很少的沉默范围是正确的.

Below is a sample implementation that I tried using an audio file. However, since silence in my case was less than half a second, only few of the silent ranges were correct.

您可能想尝试一下,通过调整min_silence_lensilence_thresh

You may want to try this and see if it works for you by tweaking min_silence_len and silence_thresh

程序

from pydub import AudioSegment,silence


myaudio = intro = AudioSegment.from_wav("a-z-vowels.wav")

silence = silence.detect_silence(myaudio, min_silence_len=1000, silence_thresh=-16)

silence = [((start/1000),(stop/1000)) for start,stop in silence] #convert to sec
print silence

结果

在Win32上使用Python 2.7.9(默认值,2014年12月10日,12:24:55)[MSC v.1500 32位(英特尔)] 键入版权",信用"或"license()"以获取更多信息.

Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information.

===============================重启============== ==================

================================ RESTART ================================

[(0,1),(1,14),(14,20),(19,26),(26,27),(28,30),(29,32),(32,34 ),(33、37),(37、41),(42、46),(46、47),(48、52)]

[(0, 1), (1, 14), (14, 20), (19, 26), (26, 27), (28, 30), (29, 32), (32, 34), (33, 37), (37, 41), (42, 46), (46, 47), (48, 52)]

这篇关于使用python从给定的音频文件中检测静音索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆