-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaudacity_to_mp3splt.py
47 lines (34 loc) · 1.13 KB
/
audacity_to_mp3splt.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import re
from os import system
"""
expected time formats:
audacity: seconds.000000
mp3splt: minutes.seconds.00
"""
def time_format(seconds_str):
seconds = int(seconds_str)
m, s = divmod(seconds, 60)
return str(m) + '.' + str(s)
chapters_file = open('audacity_labels_out.txt', 'r')
while True:
chapter_line = chapters_file.readline()
if chapter_line == '':
break
strs = chapter_line.split('\t')
t1_old = strs[0][0:-5] # time in seconds with one digit after the point
t2_old = strs[1][0:-5]
name_raw = strs[2][0:-1]
name_spaces = name_raw.replace(' ', '\ ')
name_underscores = name_raw.replace(' ', '_')
[t1_s, t1_ds] = t1_old.split('.')
[t2_s, t2_ds] = t2_old.split('.')
t1 = time_format(t1_s) + '.' + t1_ds + '0'
t2 = time_format(t2_s) + '.' + t2_ds + '0'
# original start end tags target file
command = 'mp3splt uncut.mp3 {t1} {t2} -g %[@o,@t={ns}] -o chapters/{nu}'.format(
t1=t1,
t2=t2,
ns=name_spaces,
nu=name_underscores
)
system(command)