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")
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow