How to get duration of WAV file in Python (minimal example)

Use

get_wav_duration_minimal.py
duration_seconds = mywav.getnframes() / mywav.getframerate()

to get the duration of a WAV file in seconds.

Full example:

get_wav_duration_full.py
import wave

with wave.open("myaudio.wav") as mywav:
    duration_seconds = mywav.getnframes() / mywav.getframerate()
    print(f"Length of the WAV file: {duration_seconds:.1f} s")

 


Check out similar posts by category: Audio, Python