from pydub import AudioSegment
import math
def get_audio_length(audio_file_path):
# Load the audio file
audio_file = AudioSegment.from_file(audio_file_path)
# Get the duration of the audio in seconds
duration_sec = len(audio_file) / 1000
# Round up the duration to the highest integer
duration_sec = int(math.ceil(duration_sec))
return duration_sec
I tried to use a wave module by coverting my mp3 file into a WAV file and trying to use my other programm that does the same but the same wrong answer is delivered. The seconds that are returned are clearly wrong and not just by half a second. Hope you can help me.
You can try using the audioread
module.
with audioread.audio_open(song) as song: length = int(song.duration)
This gives the length of the song in seconds. It takes a song file as the argument for audio open.