-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_segmenter.py
More file actions
85 lines (58 loc) · 2.45 KB
/
Copy pathauto_segmenter.py
File metadata and controls
85 lines (58 loc) · 2.45 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import os
import os.path
from praatio import tgio
from os.path import join
#praat textgrid creator that auto annotates freq/notes and duration
#('tier_name', [(start, stop, 'annotation'), (start, stop, 'annotation'), ...])
# takes in file_info = (float, int, str): (timestamp, length in ms, freq/undef)
#create a for loop for the objs in file info, and add those tuples to list, use list to make a textGrid interval tier, use tier to make textgrid file
def auto_segmenter(file_info, ELAN_name, do_all, operation = ''):
beat_info = []
rest_info = []
file_length = 0
ELAN_name = ELAN_name + operation
if len(file_info) == 2:
file_info = file_info[0]
#each beat in file info should look like [start, length, name]
for beat in file_info:
#creates vals for start, stop, and beat label
beat_start = float(beat[0])
beat_length = int(beat[1])/1000
beat_end = round((beat_length + beat_start), 2)
beat_label = beat[2]
if 'undefined' in beat:
rest_info.append([beat_start, beat_end, 'rest'])
continue
elif 'phrase_break' in beat:
beat_info.append([beat_start, beat_end, ''])
continue
if type(beat_label) == list:
beat_label = [x for x in beat_label if x != 'undefined']
beat_label = ' '.join(beat_label)
# else:
#adds these vals to a list
beat_info.append([beat_start, beat_end, beat_label])
#creates tier desired beat info
beat_tier = tgio.IntervalTier('Balafon', beat_info)
#nothing is left blank
# nothing = [[0, 1, '']]
#creates tiers
# karim_tier = tgio.IntervalTier('Karim', nothing)
# ktrans_tier = tgio.IntervalTier('Karim Translation', nothing)
# ant_tier = tgio.IntervalTier('Anthony', nothing)
# atrans_tier = tgio.IntervalTier('Anthony Translation', nothing)
# emile_tier = tgio.IntervalTier('Emile', nothing)
# etrans_tier = tgio.IntervalTier('Emile Translation', nothing)
#creates the textgrid and adds in the filled beat tier, and blank tiers for further annotation
file_textgrid = tgio.Textgrid()
file_textgrid.addTier(beat_tier)
# file_textgrid.addTier(karim_tier)
# file_textgrid.addTier(ktrans_tier)
# file_textgrid.addTier(ant_tier)
# file_textgrid.addTier(atrans_tier)
# file_textgrid.addTier(emile_tier)
# file_textgrid.addTier(etrans_tier)
#makes textgrid of beats of given file_info
if do_all == False :
file_textgrid.save('textgrid_data/' + ELAN_name + '.TextGrid')
return beat_info