python - 如何在 JYTHON 中混合两个声音文件?
问题描述
所以,我对编程真的很陌生,我目前正在学习JYTHON
,我需要混合两种不同的声音并将它们变成一种声音。到目前为止,我真的尽力编写了这个代码,但是每当我尝试播放结果时,空的声音文件都不会播放任何声音:<
那么请你们看看我的代码并告诉我我做错了什么吗?
def blendTwoSounds():
sound1 = pickAFile()
antelope = makeSound(sound1)
sound2 = pickAFile()
rabbit = makeSound(sound2)
jackalope = makeEmptySoundBySeconds(9)
for index in range(0,20000):
rabbitSample = getSampleValueAt(sound2, index)
setSampleValueAt(jackalope, index , sound2Sample)
for index in range(0,20000):
sound2Sample = getSampleValueAt(sound2,index+20000)
sound1Sample = getSampleValueAt(sound1, 20000)
newSample =10.0*sound2Sample + 10.9*sound2Sample
setSampleValueAt(jackalope, index+20000, newSample)
for index in range(20000,40000):
sound1Sample = getSampleValueAt(sound1,index)
setSampleValueAt(jackalope, index+20000,sound1Sample)
play(jackalope)
我什至尝试过这段代码,听起来可以,但最终结果(jackalope)里面没有任何声音。也请看一下,看看哪个更好用
def blendTwoSounds():
path1 = pickAFile()
antelope = makeSound(path1)
path2 = pickAFile()
rabbit = makeSound(path2)
jackalope = makeEmptySoundBySeconds(9)
for index in range(0,20000):
asample = getSampleValueAt(asample,index)
rsample = getSampleValueAt(rsample,index)
newSample = 9.5*asample+9.5*rsample
setSampleValueAt(jackalope,index,newSample)
for index in range(20000,40000):
rsample = getSamleValueAt(rsample,index)
setSampleValueAt(jackalope,index+20000,rsample)
play(jackalope)
return(jackalope)
所以看起来我让这段代码可以工作,但我可以让它变得更好吗?任何建议都会有帮助。
def blendTwoSounds():
path1 = pickAFile()
a = makeSound(path1)
path2 = pickAFile()
r = makeSound(path2)
jackalope = makeEmptySoundBySeconds(3)
for index in range(0,20000):
rSample = getSampleValueAt(r,index)
setSampleValueAt(jackalope,index,rSample)
for index in range(0,20000):
rSample = getSampleValueAt(r,index+20000)
aSample = getSampleValueAt(a,index)
newSample = 7.5*rSample + 7.5*aSample
setSampleValueAt(jackalope,index+20000,newSample)
for index in range(20000,40000):
aSample = getSampleValueAt(a,index)
setSampleValueAt(jackalope,index+20000,aSample)
play(jackalope)
folder=setMediaPath()
writeSoundTo(jackalope,folder+'blending.wav')
return jackalope
blendTwoSounds()
解决方案
推荐阅读
- java - 使用 thymeleaf 时使用多个页眉、页脚
- reactjs - React:使用 React-router 实现 Redux 时遇到问题
- pytorch - ModuleNotFoundError:没有名为“torch._C”的模块
- swift - 为什么这个 Swift 结构需要“变异”?
- vba - WorksheetFunction.Norm_S_Inv() 的问题
- php - 我需要保存在 URL 中的 ID 来更新数据库中的表
- apache - 如何使用 .htaccess 将 WSS 代理到 WS
- python - Pandas:如果它们出现在另一列中,则替换列中的值 - 使用第三列中的值
- c# - ASP.NET 核心 Web API:基于数据库权限的授权
- python - python中嵌套循环的一种更有效的方法