-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_pitch.praat
95 lines (85 loc) · 2.51 KB
/
check_pitch.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
# Author: Chunyu Ge 葛淳宇
# Updated: 2019-12-12
# Usage: - Check the pitch of sound files, and smooth the manually checked pitch
# - The smoothed and interpolated Pitch and PitchTier files are saved in the same directory
# Cautions: - The floor and ceiling of Pitch caculation is set to 75 and 300 for male, and 100 and 350 for female
# - If the pitch is already checked, the existed pitch and PitchTier files will be opened
# Tested on Praat 6.0.37
form What you want to do with this script
comment Where are the files?
sentence filePath C:/Users/Hu/Desktop/test/
comment Is this speaker male or female?
word gender female
endform
# path normalization
if right$(filePath$) <> "/"
filePath$ = filePath$ + "/"
endif
# usual variables
extension$ = ".wav"
tg$ = ".TextGrid"
pitch$ = ".PitchTier"
if gender$ == "male"
floor = 75
ceiling = 300
else
floor = 100
ceiling = 350
endif
# access the files/directories using `Strings`
Create Strings as file list: "fileList", filePath$ + "*" + extension$
selectObject: "Strings fileList"
stringNum = Get number of strings
for i from 1 to stringNum
selectObject: "Strings fileList"
fileName$ = Get string: i
baseName$ = fileName$ - extension$
Read from file: filePath$ + fileName$
Read from file: filePath$ + baseName$ + tg$
selectObject: "Sound " + baseName$
plusObject: "TextGrid " + baseName$
View & Edit
if fileReadable(filePath$ + baseName$ + pitch$)
Read from file: filePath$ + baseName$ + pitch$
Read from file: filePath$ + baseName$ + ".pitch"
else
selectObject: "Sound " + baseName$
To Pitch: 0, floor, ceiling
Rename: "automatic"
selectObject: "Pitch automatic"
View & Edit
pause Confirm
selectObject: "Pitch automatic"
@smooth_pitch: "automatic"
Rename: baseName$
selectObject: "Pitch interpolate"
Rename: baseName$
endif
selectObject: "Pitch " + baseName$
View & Edit
selectObject: "PitchTier " + baseName$
View & Edit
beginPause: "Save & continue"
comment: "Do you want to save and continue?"
clicked = endPause: "yes", "no", 1
if clicked = 1
selectObject: "Pitch " + baseName$
Save as text file: filePath$ + baseName$ + ".pitch"
selectObject: "PitchTier " + baseName$
Save as text file: filePath$ + baseName$ + ".PitchTier"
endif
select all
minusObject: "Strings fileList"
Remove
endfor
selectObject: "Strings fileList"
Remove
procedure smooth_pitch: .baseName$
selectObject: "Pitch " + .baseName$
Smooth: 10
Rename: "smooth"
Interpolate
Rename: "interpolate"
selectObject: "Pitch interpolate"
Down to PitchTier
endproc