What is the simplest way to determine the length (in seconds) of a given mp3 file, without using outside libraries? (python source highly appreciated)
Using Audio Tag. The easiest way to obtain the duration of an audio file is through the embed Audio tag, used to embed sound content in documents. It may contain one or more audio sources, represented using the src attribute or the <source> element nested on the audio tag.
To determine the file size of an audio file, we have to multiply the bit rate of the audio by its duration in seconds. As a result, we get file size values in terms of kilobits and megabits.
1024 / 3.28 If you really don't feel like doing all the math, you can remember that, for MP3s at a bitrate of 128 Kbps, 1 minute of audio equals about 1MB.
The maximum file size for mp3s and wavs is just under 50MB, because 50MB is the total project size limit. When scratch uploads sounds, it first turns them into wavs. This may be increasing your file size. Try manually converting your mp3 into a wav with Audacity or something similar and see how big it becomes.
You can use pymad. It's an external library, but don't fall for the Not Invented Here trap. Any particular reason you don't want any external libraries?
import mad
mf = mad.MadFile("foo.mp3")
track_length_in_milliseconds = mf.total_time()
Spotted here.
--
If you really don't want to use an external library, have a look here and check out how he's done it. Warning: it's complicated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With