-
Notifications
You must be signed in to change notification settings - Fork 36
/
textgrid_and_trim.praat
72 lines (69 loc) · 2.41 KB
/
textgrid_and_trim.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
# Grid Assistant
# Will Styler - 2020-2022
#
# This script will just open all files in a folder and generate textgrids, save the grid for the original file, then save a trimmed version (to the second interval in the grid) and amplitude normed of the file as a stimulus with the stim_ prefix
#
# This makes the script great for cleaning and reviewing stimuli.
windowtype$ = "hamming"
form We need some details here...
#choice windowtype$ hamming
# comment What kind of window would you like to extract sounds with?
# button hamming
# button rectangular
boolean viewall 0
comment Would you like to view all files (rather than just those without textgrids?)
endform
directory$ = chooseDirectory$ ("Choose the directory containing sound files for gridding")
directory$ = "'directory$'" + "/"
file_type$ = ".wav"
Create Strings as file list... list 'directory$'*'file_type$'
number_files = Get number of strings
for ifile to number_files
select Strings list
sound$ = Get string... ifile
Read from file... 'directory$''sound$'
soundname$ = selected$ ("Sound", 1)
gridfile$ = "'directory$''soundname$'.TextGrid"
badfile$ = "'directory$''soundname$'.isBad"
selectObject: "Sound 'soundname$'"
To TextGrid: "boundaries", ""
selectObject: "Sound 'soundname$'"
Scale intensity: 70
label GRIDSTEP
selectObject: "Sound 'soundname$'"
plusObject: "TextGrid 'soundname$'"
Edit
editor TextGrid 'soundname$'
beginPause ("If the sound file is fine, click OK. If the target is missing or otherwise bad , click Bad File")
skipstat = endPause ("Bad file!", "OK", 2)
endeditor
selectObject: "TextGrid 'soundname$'"
if skipstat == 1
Save as text file: "'directory$''soundname$'.isBad"
elsif skipstat == 2
intnum = Get number of intervals: 1
if intnum < 2
goto GRIDSTEP
else
selectObject: "TextGrid 'soundname$'"
Save as text file: "'directory$''soundname$'.TextGrid"
wstart = Get start point: 1, 2
wend = Get end point: 1, 2
selectObject: "Sound 'soundname$'"
if windowtype$ == "hamming"
Extract part: wstart, wend, "Hamming", 1, "no"
elsif windowtype$ == "rectangular"
Extract part: wstart, wend, "Rectangular", 1, "no"
endif
selectObject: "Sound 'soundname$'_part"
Save as WAV file: "'directory$''soundname$'.wav"
endif
endif
selectObject: "Sound 'soundname$'"
plusObject: "Sound 'soundname$'_part"
plusObject: "TextGrid 'soundname$'"
Remove
lastsound$ = soundname$
endfor
select Strings list
Remove