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]
:::

posted on   周健康  阅读(14651)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示