Python声音拼接
我正在做一个程序,这个程序可以处理音频文件,找到并去掉文件中的静音部分。目前程序可以运行,但当我们播放处理后的声音时,听起来只是原文件的慢放版本。这个功能接收一个声音文件,还有静音段的开始和结束时间。然后它会制作两个片段(一个是在静音前,一个是在静音后),并把这两个片段合并到目标声音对象中。
def spliceAudio(audio, start, stop):
clipOneStart = 0
clipOneEnd = start - 1
clipTwoStart = stop + 1
clipTwoEnd = getLength(audio) - 1
target = makeEmptySound(getLength(audio) - (stop-start))
index = 0
for source in range(clipOneStart, clipOneEnd):
value = getSampleValueAt(audio, source)
setSampleValueAt(target, index, value)
index = index + 1
for source in range(clipTwoStart, clipTwoEnd):
value - getSampleValueAt(audio, source)
setSampleValueAt(target, index, value)
index = index + 1
play(target)
return target
对我来说,所有的步骤看起来都应该能正常工作,但结果却不是我们预期的。有没有什么想法?
1 个回答
0
你的代码逻辑看起来没问题。音频播放速度常见的问题通常和你给音频数据设置的参数有关,具体包括:
- 采样频率
- 声道数量
- 位深度(可能不太相关,因为看起来数据是存储在一个数组里的)
我对jython没有经验,但从你的代码来看,调用makeEmptySound()
函数时,并没有任何迹象表明这些参数是为target
设置的。我想它们会有默认值,但值得检查一下这些默认值是什么,以及它们是否和你的输入数据匹配。