在python中的单词上拆分语音音频文件
作者:互联网
我觉得这是一个相当普遍的问题,但我还没有找到合适的答案.我有许多人类语音的音频文件,我想在单词上打破,这可以通过查看波形中的暂停来启发式地完成,但是有人能指向我自动执行此操作的python中的函数/库吗?
解决方法:
更简单的方法是使用pydub模块.最近的silent utilities增加了所有的重任,如设置沉默threahold,设置沉默长度.与提到的其他方法相比,显着简化了代码.
这是一个演示实现,灵感来自here
设定:
我在“a-z.wav”文件中有一个带有A到Z英语口语的音频文件.在当前工作目录中创建了子目录splitAudio.在执行演示代码时,文件被分成26个单独的文件,每个音频文件存储每个音节.
观察:
一些音节被切断,可能需要修改以下参数,
min_silence_len = 500
silence_thresh = -16
人们可能想要根据自己的要求调整这些.
演示代码:
from pydub import AudioSegment
from pydub.silence import split_on_silence
sound_file = AudioSegment.from_wav("a-z.wav")
audio_chunks = split_on_silence(sound_file,
# must be silent for at least half a second
min_silence_len=500,
# consider it silent if quieter than -16 dBFS
silence_thresh=-16
)
for i, chunk in enumerate(audio_chunks):
out_file = ".//splitAudio//chunk{0}.wav".format(i)
print "exporting", out_file
chunk.export(out_file, format="wav")
输出:
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 ================================
>>>
exporting .//splitAudio//chunk0.wav
exporting .//splitAudio//chunk1.wav
exporting .//splitAudio//chunk2.wav
exporting .//splitAudio//chunk3.wav
exporting .//splitAudio//chunk4.wav
exporting .//splitAudio//chunk5.wav
exporting .//splitAudio//chunk6.wav
exporting .//splitAudio//chunk7.wav
exporting .//splitAudio//chunk8.wav
exporting .//splitAudio//chunk9.wav
exporting .//splitAudio//chunk10.wav
exporting .//splitAudio//chunk11.wav
exporting .//splitAudio//chunk12.wav
exporting .//splitAudio//chunk13.wav
exporting .//splitAudio//chunk14.wav
exporting .//splitAudio//chunk15.wav
exporting .//splitAudio//chunk16.wav
exporting .//splitAudio//chunk17.wav
exporting .//splitAudio//chunk18.wav
exporting .//splitAudio//chunk19.wav
exporting .//splitAudio//chunk20.wav
exporting .//splitAudio//chunk21.wav
exporting .//splitAudio//chunk22.wav
exporting .//splitAudio//chunk23.wav
exporting .//splitAudio//chunk24.wav
exporting .//splitAudio//chunk25.wav
exporting .//splitAudio//chunk26.wav
>>>
标签:heuristics,python,audio,speech-recognition,speech 来源: https://codeday.me/bug/20190930/1836073.html