-
Notifications
You must be signed in to change notification settings - Fork 64
/
Get_Duration_From_Sound_Files.praat
78 lines (73 loc) · 2.48 KB
/
Get_Duration_From_Sound_Files.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
# This Praat script will stats total duration of all sound files or TextGrid files in a given directory
# and save result to a TXT file.
#
# This script is distributed under the GNU General Public License.
# Copyright 2020.12.06 feelins[[email protected]]
# 2020.12.06 set the sample dir
# e.g.
# [dir]-----wav
# -------------+----0001.wav
# -------------+----0001.TextGrid
# -------------+----0002.wav
# -------------+----0002.TextGrid
#
# results:
# -------------------0001.wav,2.66
# -------------------0002.wav,2.86
# -------------------0001.TextGrid,2.66
# -------------------0002.TextGrid,2.86
# -------------------total: 5.52
form dialogue
comment Directory path of input wav files:
sentence input_wav_directory wavs/
comment Directory path of input TextGrid files:
sentence input_textgrid_directory TextGrids/
comment Path of output result file:
sentence save_result duration_result.txt
endform
if (praatVersion < 6001)
printline Requires Praat version 6.0 or higher. Please upgrade your Praat version
exit
endif
deleteFile: save_result$
if input_wav_directory$ <> ""
Create Strings as file list: "fileList", input_wav_directory$ + "*.wav"
fileNumber = Get number of strings
total_duration = 0.0
for i from 1 to fileNumber
selectObject: "Strings fileList"
fileName$ = Get string: i
Read from file: input_wav_directory$ + fileName$
objectName$ = selected$ ("Sound", 1)
duraTotal = Get total duration
total_duration = total_duration + duraTotal
appendFileLine: save_result$, fileName$, ",", duraTotal
selectObject: "Sound " + objectName$
Remove
endfor
appendFileLine: save_result$, "Total wavs", ": ", total_duration
selectObject: "Strings fileList"
Remove
endif
appendFileLine: save_result$, " "
if input_textgrid_directory$ <> ""
Create Strings as file list: "fileList", input_textgrid_directory$ + "*.TextGrid"
fileNumber = Get number of strings
total_duration = 0.0
for i from 1 to fileNumber
selectObject: "Strings fileList"
fileName$ = Get string: i
Read from file: input_textgrid_directory$ + fileName$
objectName$ = selected$ ("TextGrid", 1)
# duraTotal = Get total duration
duraTotal = Get total duration of intervals where: 1, "is not equal to", ""
total_duration = total_duration + duraTotal
appendFileLine: save_result$, fileName$, ",", duraTotal
selectObject: "TextGrid " + objectName$
Remove
endfor
appendFileLine: save_result$, "Total TextGrids", ": ", total_duration
selectObject: "Strings fileList"
Remove
endif
exit Done!Thank you!-shaopf