gpt4 book ai didi

python - pydub 附加 - 引擎盖下行为的澄清

转载 作者:行者123 更新时间:2023-12-02 22:31:31 25 4
gpt4 key购买 nike

我一直在使用 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) != 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() 下。

AudioSegment(…).append()

Returns a new AudioSegment, created by appending another AudioSegment to this one (i.e., adding it to the end), Optionally using a crossfade. AudioSegment(…).append() is used internally when adding AudioSegment objects together with the + operator.

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

Supported keyword arguments:

  • crossfade | example: 3000 | default: 100 (entire duration of AudioSegment) When specified, method returns number of frames in X milliseconds of the AudioSegment

最佳答案

我可以确认使用 + 运算符的连接不会应用任何淡入淡出(实际上是 calls the append method with crossfade=0 )

该设计决定的原因是允许使用 sum() 和 reduce() 以及其他类似的方法将一堆 block 放回一起而不改变总持续时间(由于淡入淡出重叠)

关于python - pydub 附加 - 引擎盖下行为的澄清,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50938152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com