forked from stylerw/styler_praat_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
styler_vowel_splicer.praat
172 lines (155 loc) · 5.48 KB
/
styler_vowel_splicer.praat
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# CU Phonetics Lab Script
#
# Version 0.5.0
#
# This is designed to take a marked segment in one word and splice it into a bunch of other words
# You'll need to create an 'output' folder in whatever directory you're working.
# Here's hoping it works.
# Will Styler, 9/2/2010
#
# This part presents a form to the user
form Splice donor segment into recipients
comment Donor Sound File:
text donorfile bryce_rcite-band
comment Tiers in the TextGrid for:
integer vowel 1
integer word 2
comment Sound file extension:
optionmenu file_type: 2
option .aiff
option .wav
endform
window = 0.0256
directory$ = chooseDirectory$ ("Choose the directory containing sound files and textgrids")
directory$ = "'directory$'" + "/"
# List of all the sound files in the specified directory:
Create Strings as file list... list 'directory$'*'file_type$'
number_files = Get number of strings
# Steps:
# 1: Get recip word
# 2: Cut out recip vowel
# 3: Identify donor word
# 4: Cut out donor vowel
# 5: Amplitude match both vowels
# 9: Paste the resulting vowel into the donor or recip (or both) word context
# 10: Save output
# 11: Repeat for all files in the folder
#
donorexists = 0
for j from 1 to number_files
# 1: Get recip word
# Remember that we only stored recip words in the stringslist above
select Strings list
filename$ = Get string... 'j'
Read from file... 'directory$''filename$'
soundname$ = selected$ ("Sound")
filedur = Get total duration
# identify associated TextGrid
gridfile$ = "'directory$''soundname$'.TextGrid"
if fileReadable (gridfile$)
Read from file... 'gridfile$'
select TextGrid 'soundname$'
number_intervals = Get number of intervals... 'vowel'
for k from 1 to number_intervals
select TextGrid 'soundname$'
vowel_label$ = Get label of interval... 'vowel' 'k'
#checks if interval has a labeled vowel
if vowel_label$ <> ""
rstart = Get starting point... 'vowel' 'k'
rcursor = rstart
rend = Get end point... 'vowel' 'k'
rmidpoint = rstart + ((rend - rstart) / 2)
rdur = rend - rstart
select Sound 'soundname$'
Copy... 'soundname$'_unedited
select Sound 'soundname$'
# Drop into a point process to get the start of the cycle at start and end, not just a zero crossing.
To PointProcess (periodic, cc)... 75 300
spulse = Get nearest index... rstart
spulsetime = Get time from index... spulse
epulse = Get nearest index... rend
epulsetime = Get time from index... epulse
select Sound 'soundname$'
rstartz = Get nearest zero crossing... 1 spulsetime
Extract part... 0 rstartz rectangular 1 no
Rename... wordstart
select Sound 'soundname$'
rendz = Get nearest zero crossing... 1 epulsetime
Extract part... rendz filedur rectangular 1 no
Rename... wordend
select Sound 'soundname$'
Extract part... rstartz rendz rectangular 1 no
Rename... recipbefore
recip_DB = Get intensity (dB)
select Sound recipbefore
rvoweldur = Get total duration
endif
endfor
endif
# 3: Identify donor pair
if donorexists = 0
Read from file... 'directory$''donorfile$''file_type$'
dsoundname$ = selected$ ("Sound")
dgridfile$ = "'directory$''donorfile$'.TextGrid"
if fileReadable (dgridfile$)
Read from file... 'dgridfile$'
select TextGrid 'dsoundname$'
number_intervals = Get number of intervals... 'vowel'
for k from 1 to number_intervals
select TextGrid 'dsoundname$'
dvowel_label$ = Get label of interval... 'vowel' 'k'
#checks if interval has a labeled vowel
if dvowel_label$ <> ""
dstart = Get starting point... 'vowel' 'k'
dend = Get end point... 'vowel' 'k'
dmidpoint = dstart + ((dend - dstart) / 2)
select Sound 'dsoundname$'
Copy... 'dsoundname$'_unedited
select Sound 'dsoundname$'
# Drop into a point process to get the start of the cycle at start and end, not just a zero crossing.
To PointProcess (periodic, cc)... 75 300
dspulse = Get nearest index... dstart
dspulsetime = Get time from index... dspulse
depulse = Get nearest index... dend
depulsetime = Get time from index... depulse
select Sound 'dsoundname$'
dstartz = Get nearest zero crossing... 1 dspulsetime
dendz = Get nearest zero crossing... 1 depulsetime
Extract part... dstartz dendz rectangular 1 no
Rename... donor
dvoweldur = Get total duration
donorexists = 1
endif
endfor
endif
endif
# 9: Paste the resulting vowel into the recip context
select Sound wordstart
Copy... wordstartcat
select Sound wordend
Copy... wordendcat
select Sound wordendcat
plus Sound donor
Concatenate
plus Sound wordstartcat
Concatenate
Rename... recipwordnew
# 10: Save output
select TextGrid 'soundname$'
Remove right boundary... 'vowel' 1
Remove right boundary... 'vowel' 1
Insert boundary... 'vowel' rstartz
secondpoint = rstartz + dvoweldur
Insert boundary... 'vowel' secondpoint
Set interval text... 1 1
Set interval text... 1 2 V
select TextGrid 'soundname$'
Write to text file... 'directory$'output/'soundname$'_withsplice_.TextGrid
select Sound recipwordnew
Write to WAV file... 'directory$'output/'soundname$'_withsplice_.wav
select all
minus Strings list
minus Sound donor
Remove
endfor
# This closes the for loop if we're iterating