-
Notifications
You must be signed in to change notification settings - Fork 8
/
count_length.py
26 lines (21 loc) · 992 Bytes
/
count_length.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
# using pydub, read all of the files in the /wavs folder, add up the total length and print
from pydub import AudioSegment
import glob
def get_length(filename):
song = AudioSegment.from_wav(filename)
return len(song)
def get_total_length(filenames):
total_length = 0
for filename in filenames:
total_length += get_length(filename)
return total_length
if __name__ == "__main__":
#glob all files in the wavs folder and call get_total_length
filenames = glob.glob('./wavs/*.wav')
total_length = get_total_length(filenames)
print("Total length of " + str(len(filenames)) + " files: " + str(total_length/1000) + "s" + " or " + str(total_length/60000) + "m")
# get the longest file
longest = max(filenames, key=get_length)
shortest = min(filenames, key=get_length)
print("Longest file: " + longest + " at " + str(get_length(longest)/1000) + "s")
print("Shortest file: " + shortest + " at " + str(get_length(shortest)/1000) + "s")