如何在 Python 中获取 WAV 文件的时长(最小示例)
使用
get_wav_duration_minimal.py
duration_seconds = mywav.getnframes() / mywav.getframerate()以秒为单位获取 WAV 文件的时长。
完整示例:
get_wav_duration_full.py
import wave
with wave.open("myaudio.wav") as mywav:
duration_seconds = mywav.getnframes() / mywav.getframerate()
print(f"WAV 文件的长度: {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