我正在尝试创建一个函数,该函数将从一个文件夹中的多个wav文件中删除人声,但仍会遇到索引错误。我是python的新手,所以不确定该问题是从哪里引起的,但我认为这可能源于我在函数调用中引用文件路径的方式,尽管我不确定。有什么建议吗?
from pydub import AudioSegment
from pydub.playback import play
def vocalremover(advertaudio):
sound_stereo = AudioSegment.from_wav(advertaudio)
sound_monoR = sound_stereo.split_to_mono()[1]
sound_monoL = sound_stereo.split_to_mono()[0]
sound_monoR_inv = sound_monoR.invert_phase()
sound_CentersOut = sound_monoL.overlay(sound_monoR_inv)
sound_CentersOut.export(str(advertaudio), format="wav")
vocalremover(r'C:\Users\Jan\OneDrive - Media
Ltd\normalized\201901150009_Proxy.wav')
它返回错误:
IndexError Traceback(最近一次通话最近) 在 ----> 1 vocalremover(r'C:\ Users \ Jane \ OneDrive-Jeli Media Ltd \ clearcast \ normalized \ 201901150009_Proxy.wav')
在vocalremover(advertaudio)中
----> 9 sound_monoR = sound_stereo.split_to_mono()[1]
IndexError:列表索引超出范围
答案 0 :(得分:0)
def vocalremover(advertaudio):
sound_stereo = AudioSegment.from_wav(advertaudio)
sound_monoR = sound_stereo.split_to_mono()[0][1]
sound_monoL = sound_stereo.split_to_mono()[0][0]
sound_monoR_inv = sound_monoR.invert_phase()
sound_CentersOut = sound_monoL.overlay(sound_monoR_inv)
sound_CentersOut.export(str(advertaudio), format="wav")
做到这一点有效,但是文件似乎无法播放任何内容,请尝试一下并进行报告