duration()¶
- audiofile.duration(file, sloppy=False)[source]¶
Duration in seconds of audio file.
The default behavior (
sloppy=False) ensures the duration in seconds matches the one in samples. To achieve this it first decodes files to WAV if needed, e.g. MP4 files. If you have different decoders on different machines, results might differ.The case
sloppy=Truereturns the duration as reported in the header of the audio file. This is faster, but might still return different results on different machines as it depends on the installed software. If no duration information is provided in the header it will fall back tosloppy=False.- Parameters:
- Return type:
- Returns:
duration in seconds of audio file
- Raises:
FileNotFoundError – if ffmpeg or mediainfo binary is needed, but cannot be found
RuntimeError – if
fileis missing, broken or format is not supported
Examples
>>> audiofile.duration("stereo.wav") 1.5