Get .wav file length or duration

后端 未结 9 733
暗喜
暗喜 2020-12-04 10:17

I\'m looking for a way to find out the duration of a audio file (.wav) in python. So far i had a look at python wave library, mutagen, pymedi

9条回答
  •  旧巷少年郎
    2020-12-04 10:45

    To find length of music file, audioread module can be used,

    install audioread: pip install audioread

    then use this code:

    import audioread
    with audioread.audio_open(filepath) as f:
        totalsec = f.duration
        min,sec = divmod(totalsec,60) # divides total time in minute  and second 
                                        #and store it in min and sec variable respectively
    

提交回复
热议问题