Python pydub append-发动机罩下行为的澄清
我一直在使用pydub将短的声音文件连接到一个更大的声音文件中。这方面的基本代码如下所示:Python pydub append-发动机罩下行为的澄清,python,python-3.x,audio,pydub,Python,Python 3.x,Audio,Pydub,我一直在使用pydub将短的声音文件连接到一个更大的声音文件中。这方面的基本代码如下所示: def permuPhrase(iterations, joins): # Builds a single phrase and does various permutations of it sampleSet = entryMatcher() sampleSet.inputVars() sampleSet.match() concat = 0 if len(sampleSet.results) !=
def permuPhrase(iterations, joins): # Builds a single phrase and does various permutations of it
sampleSet = entryMatcher()
sampleSet.inputVars()
sampleSet.match()
concat = 0
if len(sampleSet.results) != 0:
for x in range(iterations):
for i in range(joins):
rand = rn.randint(0, len(sampleSet.results)- 1)
choice = str(sampleSet[rand])
concat += (AudioSegment.from_wav(source+choice+affix))
numIter = str(x) # convert parent for loop to string for naming .wav files.
concat.export(newDir+numIter+affix, format="wav") # export
else:
print("No samples matched")
我的问题是。在API中,它表示默认情况下有100毫秒的交叉淡入。但是,下面给出的示例表明,如果使用+运算符连接样本,则不会使用交叉淡入淡出。我想知道是否有人能澄清这一点?我链接了API,因为复制示例是不可读的。它位于AudioSegment(…).append()下
音频段(…).append()
返回一个新的音频段
,该音频段是通过附加另一个音频段创建的
AudioSegment
添加到此段(即,将其添加到末尾),可选
使用交叉淡入淡出<代码>音频段(…).append()在
将AudioSegment
对象与+
操作符一起添加
默认情况下,使用100毫秒(0.1秒)的交叉淡入消除POP
还有爆裂声
from pydub import AudioSegment
sound1 = AudioSegment.from_file("sound1.wav")
sound2 =AudioSegment.from_file("sound2.wav")
# default 100 ms crossfade
combined = sound1.append(sound2)
# 5000 ms crossfade
combined_with_5_sec_crossfade = sound1.append(sound2, crossfade=5000)
# no crossfade
no_crossfade1 = sound1.append(sound2, crossfade=0)
# no crossfade
no_crossfade2 = sound1 + sound2
支持的关键字参数:
|示例:crossfade
|默认值:3000
(音频段的整个持续时间))指定时,方法返回X中的帧数100
音频段的毫秒数
我可以确认使用
+
操作符的连接不会应用任何交叉淡入(事实上)
该设计决策的原因是允许使用sum()和reduce()以及其他类似的方法将一组块重新组合在一起,而不改变总持续时间(由于交叉淡入淡出重叠)