Get .wav file length or duration

后端 未结 9 740
暗喜
暗喜 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:55

    we can use ffmpeg to get the duration of any video or audio files.

    To install ffmpeg follow this link

    import subprocess
    import re
    
    process = subprocess.Popen(['ffmpeg',  '-i', path_of_wav_file], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    stdout, stderr = process.communicate()
    matches = re.search(r"Duration:\s{1}(?P\d+?):(?P\d+?):(?P\d+\.\d+?),", stdout, re.DOTALL).groupdict()
    
    print(matches['hours'])
    print(matches['minutes'])
    print(matches['seconds'])
    

提交回复
热议问题