问题描述
我一直在使用pydub将短声音文件连接成更大的声音文件.基本代码如下:
I've been using pydub to concatenate short sound files into a larger sound file. The basic code for this looks like this:
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中,它指出默认情况下存在100ms淡入淡出.但是,下面给出的示例建议,如果使用+运算符来连接样本,则不使用交叉淡入淡出.我想知道是否有人可以澄清这一点?我链接了API,因为无法复制示例.它位于AudioSegment(...).append()下.
My question is this. In the API it states there is by default an 100ms crossfade. However, the example given below suggests that if you use a + operator to concatenate samples it uses no crossfade. I was wondering if anyone can clarify this? I've linked the API as copying the example was not readable. It's under AudioSegment(...).append().
默认情况下,使用100毫秒(0.1秒)淡入淡出效果来消除爆裂声 和裂纹.
By default a 100ms (0.1 second) crossfade is used to eliminate pops and crackles.
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
|默认值:100
(整个持续时间AudioSegment
)指定时,方法以X为单位返回帧数AudioSegment
的毫秒数
crossfade
| example:3000
| default:100
(entire duration ofAudioSegment
) When specified, method returns number of frames in X milliseconds of theAudioSegment
推荐答案
我可以确认使用+
运算符进行的级联不会应用任何交叉淡入淡出(实际上是调用带有crossfade = 0 的append方法
I can confirm that concatenation using the +
operator doesn’t apply any cross fade (and in fact calls the append method with crossfade=0)
做出设计决定的原因是允许使用sum()和reduce()以及其他类似方法将一堆块放回去而不会改变总持续时间(由于交叉淡入淡出的重叠)
The reason for that design decision was to allow using sum() and reduce() and other similar methods to put a bunch of chunks back together without altering the total duration (due to the crossfade overlaps)
这篇关于pydub append-引擎盖下行为的澄清的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!