-
Notifications
You must be signed in to change notification settings - Fork 0
/
silences-param.praat
89 lines (73 loc) · 3.14 KB
/
silences-param.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
form Test
sentence indir c:\temp\wav
sentence outdir c:\temp\TextGrid
integer trunc 0
real sound_min 0.03
real silence_min 0.1
real ints_ratio 0.01
endform
appendInfoLine: outdir$
@files: indir$, outdir$, trunc, sound_min, silence_min, ints_ratio
procedure files: .indir$, .outdir$, .trunc, .sound_min, .silence_min, .ints_ratio
strings = Create Strings as file list: "list", .indir$ + "\*.wav"
numberofFiles = Get number of strings
for ifile to numberofFiles
selectObject: strings
file$ = Get string: ifile
Read from file: .indir$ + "\" + file$
#strip off file ext and replace . with _ so we can reference the object later
obj$ = replace$(left$(file$,length(file$)-4),".","_",0)
#appendInfoLine: obj$
selectObject: "Sound " + obj$
numch = Get number of channels
if numch = 2
#start the NL calls after the beep and truncate all the CGN files before the end-of-call recording starts
if .trunc != 0
if .trunc = 2
Extract part: 1.7, 566.5, "rectangular", 1, "yes"
else
#.trunc = 1
Extract part: 0, 566.5, "rectangular", 1, "yes"
endif
selectObject: "Sound " + obj$
Remove
selectObject: "Sound " + obj$ + "_part"
Rename: obj$
endif
Extract all channels
@silences: 1, .outdir$, obj$
@silences: 2, .outdir$, obj$
#combine the two textgrids (for reference)
selectObject: "TextGrid " + obj$ + "_ch1", "TextGrid " + obj$ + "_ch2"
Merge
Save as text file: .outdir$ + "\" + obj$ + "_" + string$(.sound_min) + "_" + string$(.silence_min) + "_" + string$(.ints_ratio) + "_both_ch.TextGrid"
Remove
selectObject: "TextGrid " + obj$ + "_ch1"
Remove
selectObject: "TextGrid " + obj$ + "_ch2"
Remove
endif
selectObject: "Sound " + obj$
Remove
endfor
selectObject: "Strings list"
Remove
endproc
procedure silences: .ch, .outdir$, .obj$
selectObject: "Sound " + .obj$ + "_ch" + string$(.ch)
To Intensity: 200, 0.001, "yes"
max_db = Get maximum: 0, 0, "Parabolic"
max_amp = 10**(max_db/20)
#find difference from amplitude 32768 - setting the sound/silence threshold to a percentage of the max amplitude
db = -20*log10(max_amp/(ints_ratio * 32768))
intsFile$ = .outdir$ + "\ints.txt"
appendFileLine: intsFile$, .obj$ + " " + string$(.ch) + " " + string$(max_db) + " " + string$(max_amp) + " " + string$(db)
To TextGrid (silences): db, silence_min, sound_min, "silent", "sounding"
Save as text file: .outdir$ + "\" + .obj$ + "_ch" + string$(.ch) + ".TextGrid"
selectObject: "Intensity " + .obj$ + "_ch" + string$(.ch)
Remove
selectObject: "TextGrid " + .obj$ + "_ch" + string$(.ch)
#Remove
selectObject: "Sound " + .obj$ + "_ch" + string$(.ch)
Remove
endproc