-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
33 lines (30 loc) · 826 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import wave
from mutagen.mp3 import MP3
import contextlib
import math
import subprocess
def get_wav_duration(path):
with contextlib.closing(wave.open(path,'r')) as f:
frames = f.getnframes()
rate = f.getframerate()
duration = frames / float(rate)
return duration
"""
def get_mp3_duration(path):
name = path.split(".")[0]
file_path_wav = name + ".wav"
subprocess.run(["ffmpeg", "-i", path, file_path_wav], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
duration = get_wav_duration(file_path_wav)
os.remove(file_path_wav)
return duration
"""
def get_time(seconds):
hours = 0
minutes = 0
if seconds > 3600:
hours = math.floor(seconds/3600)
seconds = seconds - hours*3600
if seconds > 60:
minutes = math.floor(seconds/60)
seconds = seconds - minutes * 60
return hours, minutes, seconds