#测试程序
import os
from pydub import AudioSegment #已经确定, # enPath = "%s%s/%s"%(enDir,file,enfile) #英文文件的路径 # cnPath = "%s%s/%s"%(cnDir,file,enfile.replace("en_w","cn_w"))#中文文件的路径 path1 = "C:\\Users\\Administrator\\Desktop\\233春晓.mp3"
p1,f1=os.path.split(path1)
# sound1 = AudioSegment.from_file(path1, format=os.path.splitext(f1)[1][-3:]) sound1 = AudioSegment.from_mp3(path1) print(len(sound1))
sound_mix = AudioSegment.empty()
print(len(sound_mix))
data_play = ['', ',', '', '.', '', ',', '', '.', '', ',', '', '.']
time_end = int(data_play[0])*100
print(time_end)
# sound_mix = sound_mix + sound1[1,time_end]
sound_mix = sound1[0,3300]
print(len(sound_mix)) # song1 = AudioSegment.from_mp3(enPath) # song2 = AudioSegment.from_mp3(cnPath)
问题显示:
22544
0
3300
Traceback (most recent call last):
File "C:\Users\Administrator\OneDrive\Mufasa Code\audio lay\test_数据读取的音频合成.pyw", line 26, in <module>
sound_mix = sound1[0,3300]
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\pydub\audio_segment.py", line 247, in __getitem__
end = millisecond + 1
TypeError: can only concatenate tuple (not "int") to tuple
请按任意键继续. . .
原因:
sound_mix = sound1[0,3300]
应该为数组类型
sound1[0:3300]
:::