can only concatenate tuple (not "int") to tuple問題原因


 1 #測試程序
 2 import os
 3 from pydub import AudioSegment     #已經確定,
 4 
 5 # enPath = "%s%s/%s"%(enDir,file,enfile) #英文文件的路徑
 6 
 7 # cnPath = "%s%s/%s"%(cnDir,file,enfile.replace("en_w","cn_w"))#中文文件的路徑
 8 
 9 
10 
11 path1 = "C:\\Users\\Administrator\\Desktop\\233春曉.mp3"
12 p1,f1=os.path.split(path1)
13 # sound1 = AudioSegment.from_file(path1, format=os.path.splitext(f1)[1][-3:])
14 
15 
16 sound1 = AudioSegment.from_mp3(path1)
17 
18 
19 print(len(sound1))
20 sound_mix = AudioSegment.empty()
21 print(len(sound_mix))
22 data_play = ['33', ',', '19', '.', '49', ',', '32', '.', '34', ',', '43', '.']
23 time_end = int(data_play[0])*100
24 print(time_end)
25 # sound_mix = sound_mix + sound1[1,time_end]
26 sound_mix = sound1[0,3300]
27 print(len(sound_mix))
28 
29 
30 
31 # song1 = AudioSegment.from_mp3(enPath)
32 
33 # 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]
:::


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM