Finding the length of an mp3 file

前端 未结 5 1368
孤城傲影
孤城傲影 2020-12-09 09:02

So i have the code:

import glob,os
import random


path = \'C:\\\\Music\\\\\'
aw=[]
for infile in glob.glob( os.path.join(path,\'*.mp3\') ):
    libr = infil         


        
5条回答
  •  生来不讨喜
    2020-12-09 09:37

    You can also get this using eyed3, if that's your flavor by doing:

    import eyed3
    duration = eyed3.load('path_to_your_file.mp3').info.time_secs
    

    Note however that this uses sampling to determine the length of the track. As a result, if it uses variable bit rate, the samples may not be representative of the whole, and the estimate may be off by a good degree (I've seen these estimates be off by more than 30% on court recordings).

    I'm not sure that's much worse than other options, but it's something to remember if you have variable bit rates.

提交回复
热议问题