-
Notifications
You must be signed in to change notification settings - Fork 36
/
get_all_durations.praat
35 lines (31 loc) · 1.21 KB
/
get_all_durations.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
# Duration Finder
# Will Styler, 2012
#
# This script measures the duration (in seconds and milliseconds) of every file in a folder and dumps to a file. It's awesome, and great for getting durations for reaction time expts.
#
# This part presents a form to the user
form Measure stuff iteratively
comment Sound file extension:
optionmenu file_type: 2
option .aiff
option .wav
endform
directory$ = chooseDirectory$ ("Choose the directory containing sound files and textgrids")
directory$ = "'directory$'" + "/"
resultfile$ = "'directory$'"+"durationlog.txt"
header_row$ = "filename" + tab$ + "seconddur" + tab$ + "milliseconddur" + newline$
fileappend "'resultfile$'" 'header_row$'
# 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
# This opens all the files one by one
for j from 1 to number_files
select Strings list
filename$ = Get string... 'j'
Read from file... 'directory$''filename$'
dur = do ("Get total duration")
msdur = dur *1000
# Dump results into a file.
result_row$ = "'filename$'" + tab$ + "'dur'" + tab$ + "'msdur'" + newline$
fileappend "'resultfile$'" 'result_row$'
endfor