├── output.png ├── output2.png ├── create-pictures-selected-sound.praat ├── .gitignore ├── README.md ├── create-pictures-selected-sound-and-textgrid.praat └── create_pictures.praat /output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wendyelviragarcia/create_pictures/HEAD/output.png -------------------------------------------------------------------------------- /output2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wendyelviragarcia/create_pictures/HEAD/output2.png -------------------------------------------------------------------------------- /create-pictures-selected-sound.praat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wendyelviragarcia/create_pictures/HEAD/create-pictures-selected-sound.praat -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore for R code 2 | 3 | # Ignore OS generated files # 4 | ###################### 5 | .DS_Store 6 | .DS_Store? 7 | ._* 8 | .Spotlight-V100 9 | .Trashes 10 | ehthumbs.db 11 | Thumbs.db 12 | 13 | ### R ### 14 | # History files 15 | .Rhistory 16 | .Rapp.history 17 | 18 | # Session Data files 19 | .RData 20 | .RDataTmp 21 | 22 | # User-specific files 23 | .Ruserdata 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Create Pictures 3 | This folder contains a three scripts for creating a spectrogram figure (with or without annotation) of a sound file in Praat. Choose the script that serves your purpose better and download that .praat file. 4 | - "create_pictures.praat": Creates pictures for all files in a folder 5 | - "create-pictures-selected-sound.praat": Creates a picture for a selected sound, already open and selected at Praat (without annotation) 6 | - " create-pictures-selected-sound-and-textgrid.praat": Creates a picture for a selected sound and TextGrid, both need to be already open and selected at Praat (with annotation) 7 | 8 | > [!WARNING] 9 | > I am currently adapting the scripts to the new "To Pitch (filtered)" function, use the latest version of Praat to avoid errors. Also be aware that you migh use a pitch ceiling higher than usual if you set that manually. 10 | 11 | # Output 12 | ![image](output.png) 13 | ![image](output2.png) 14 | 15 | 16 | 17 | # DESCRIPTION 18 | This script creates and saves pictures (PNG, PDF, wmf, eps, PraatPic) of all the Sound and TextGrid files it finds in a folder. 19 | 20 | The pictures contain a waveform (optional), a spectrogram(optional), intensity track (optional), formant track (optional) and the F0 track (optional) and a the content of the tiers of the TextGrid associated with the sound file (optional). 21 | 22 | The script is designed to carry out some operations automatically: 23 | 24 | 1. If you are drawing a TextGrid, it recognizes automatically the number of tiers in EACH textgrid and draws the picture consequently (i.e. in the picture there will be no unnecessary white space between the tiers and the spectrogram). 25 | 2. It converts the TextGrid to backslash trigraphs before drawing, so you won't have problems plotting symbols like % or ¡ 26 | 3. It detects automatically the F0 range of the picture of EACH sentence (unless you choose to specify it manually). 27 | 4. In order to correct those cases in which Praat detects F0 in fricatives (what Boersma calls "to hallucinate pitches") the script gets the pitch from a filtered sound in which all frequencies beyond 1000Hz have been cancelled. 28 | 5. It establishes automatically the number of marks on the y axis and their placement. It places the first mark at the lowest multiple of 50 Hz within the range of the picture (e.g. at 50 Hz, or 100 Hz, or 150 Hz...). The following marks are placed every 50/100/150 Hz (depending on the range of the utterance). 29 | 30 | In the INSTRUCTIONS section you will find details about the other characteristics and options of the script (e.g changing the dynamic range, choosing the level of smooth in the F0 track, changing the axis' names, choosing the speakers range of F0...) 31 | 32 | 33 | # INSTRUCTIONS 34 | The specific instructions for each script are detailed at the beggining of the .praat file. Remember a Praat file is only a .txt file that you can open with your **plain** text editor (such as Notepad++, Sublimetext, Atom...) 35 | 36 | 37 | # CREDITS 38 | Feedback is always welcome, please if you notice any bugs or come up with anything that can improve this script, let me know! 39 | Wendy Elvira-García 40 | www.wendyelvira.ga 41 | october 2013 42 | tested on Praat 6 for Windows and Mac 43 | 44 | **Citation: Elvira García, Wendy (2022). Create pictures with tiers v.6. Praat script.** 45 | 46 | The first version of this script was inspired by: 47 | draw-waveform-sgram-f0.praat 48 | Pauline Welby (2003) with the modifications made by Paolo Roseano (2011) 49 | 50 | # LICENSE 51 | Copyright (C) 2017 Wendy Elvira 52 | 53 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 54 | 55 | This program is distributed in the hope that it will be useful, 56 | but WITHOUT ANY WARRANTY; without even the implied warranty of 57 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 58 | GNU General Public License for more details. 59 | 60 | You can find the terms of the GNU General Public License here 61 | http://www.gnu.org/licenses/gpl-3.0.en.html 62 | 63 | -------------------------------------------------------------------------------- /create-pictures-selected-sound-and-textgrid.praat: -------------------------------------------------------------------------------- 1 | ############################################################################################################################################################################################ 2 | # 3 | # create_pictures-with-tiers.praat (v.4.1 -March 2015-) 4 | # Laboratori de Fonètica (Universitat de Barcelona) 5 | # 6 | # DESCRIPTION 7 | # This script creates and saves pictures (PNG, PDF, wmf, eps, PraatPic) of a selected sound and opcionally textgrid. 8 | # The pictures contain a waveform, a spectrogram, an optional F0 track and a the content of the tiers of the TextGrid associated with the sound file. 9 | # 10 | # The script is designed to carry out some operations automatically: 11 | # 1) It detects automatically the F0 range of the picture of EACH sentence (unless you choose to specify it manually). 12 | # 2)In order to correct those cases in which Praat detects F0 in fricatives (what Boersma calls "to hallucinate pitches")the script gets 13 | # the pitch from a filtered sound in which all frecuencies beyond 1000Hz have been cancelled. 14 | # 2) It recognizes automatically the number of tiers in EACH textgrid and draws the picture consequently (i.e. in the picture there will be 15 | # no unnecessary white space between the tiers and the spectrogram). 16 | # 3) It establishes automatically the number of marks on the y axis and their placement. It places the first mark at the lowest multiple of 50 Hz within the range 17 | # of the picture (e.g. at 50 Hz, or 100 Hz, or 150 Hz...). The following marks are placed every 50/100/150 Hz (depending on the range of the utterance). 18 | # In the INSTRUCTIONS section you will find details about the other characteristics and options of the script (e.g changing the dynamic range, 19 | # choosing the level of smooth in the F0 track, changing the axis' names, choosing the speakers range of F0...) 20 | # 21 | # 22 | # 23 | # INSTRUCTIONS 24 | # 0. Before you start: Create the TextGrids with the same name of the sound they are made for. Save them in a folder. 25 | # 26 | # 1. Open the script (Open/Read from file...), click Run in the upper menu and Run again. 27 | # 2. Set the parameters. 28 | # a) The 3 first fields are for the folders where you have your files. In the first field, write the name of the folder where you have your sound files. 29 | # In the second field, write the name of the folder where you have your Textgrids. In the third field, write the name of the folder where 30 | # you want the pictures to be saved. Important: always write the path without bar at the end "/". 31 | # b) By changing the dynamic range you can make your spectrograms look 'cleaner'. The lowest it is, the lighter the spectrogram looks. 32 | # c) Choose whether you want to draw the F0 curve or not. The F0 curve will be written twice, once in white and once in thinner black (Welby 2003). 33 | # d) Then specify if you want the F0 range to be defined automatically or manually. If you choose to set it manually, 34 | # in the next window you'll be asked to define the F0 minimum and F0 maximum. 35 | # e) Choose if you want the F0 minimum and F0 maximum marks to appear on the y axis (if you place them, they might overlap with other marks). 36 | # Note that the F0 minimum and F0 maximum marks are placed at 'rounded' values, that means that 377.8 Hz is rounded to 380 Hz and 51.2 Hz is rounded to 50 Hz. 37 | # f) Decide how much you want the F0 curve to be smoothed. In this field, you need to enter the bandwidth (in Hertz). If you want a 38 | # very smoothed curve, you should choose a smaller bandwidth (e.g. 10), whereas if you want a less smoothed curve you should choose a bigger bandwidth (e.g. 50). 39 | # Don't write 0 in here, because your curve would become plain. 40 | # g)In the next two choice menus, you can choose the label of the axes (in different languages). You can also decide not to label either or both of them. 41 | # h) You can change the picture width. 42 | # i)Mark the formats in which you want to save the pictures. Notice that PDF will only run if you are working on a Mac and wmf is only for Windows. PNG for Windows and presumably Linux. 43 | # j)Mark whether you want more options or not. (See below for details) 44 | # Click OK 45 | # 46 | # MORE OPTIONS WINDOW 47 | # If you chose the more options button or if you chose to set the speaker's range manually, a new window will appear. In this window you can: 48 | # a) Set the F0 range in the picture. You must write the numbers separated by a hyphen. This field will only appear if you chose "Set the range manually" 49 | # in the previous form. 50 | # b) Choose the spectrogram range. This is by default from 0 to 5000Hz. 51 | # c) If you have chosen not to draw the F0 curve, you can select here how many marks of frequency you want in the spectrogram. 52 | # You'll be asked every how many Hz you want a mark. 53 | # d) Change the time marks of the x axis. By default, there is a mark without number at every 0.2 seconds and a mark with number at every 0.5 (the number appears 54 | # written above the mark.) 55 | # e) If you are drawing the f0 curve and you've chosen "Show more options", you can choose here how do you want Praat to select the better candidates to be F0. 56 | # The script runs with the autocorrelation method (Boersma, 1993) which is optimized for human intonation research, so if you are working with speech, 57 | # you don't need to change anything. 58 | # Here you'll be asked for the octave cost, octave jump cost, the voiced/unvoiced cost and the voicing_threshold. 59 | # 60 | # 61 | # 62 | # Click OK (the Revert button goes back to the Standards of the form) 63 | # 64 | # 3. Now search your pictures, they have to be in the folder you specified in the first form. 65 | # 66 | # 67 | # 68 | # CREDITS 69 | # Feedback is always welcome, please if you notice any bugs or come up with anything that can improve this script, let me know! 70 | # 71 | # Wendy Elvira-García 72 | # wendyelviragarcia@gmail.com 73 | # october 2013 74 | # tested on Praat 5.3.73 for Windows and Mac 75 | # If it doesn't run on Linux, check the syntax of lines: 470 & 486 and mail me I'll be grateful. 76 | # 77 | # Citation: Elvira García, Wendy & Roseano, Paolo (2014). Create pictures with tiers. Praat script. (Retrieved from http://stel.ub.edu/labfon/en/praat-scripts) 78 | # 79 | # The first version of this script was inspired by: 80 | # draw-waveform-sgram-f0.praat 81 | # Pauline Welby (2003) with the modifications made by Paolo Roseano (2011) 82 | # 83 | # 84 | ################################################################################################################################### 85 | # PREDEFINED VARIBLES 86 | 87 | spectrogram_maximum_frequency = 5000 88 | frequency_marks_every= 1000 89 | 90 | #variables para el tiempo cada (ms) 91 | time_mark_with_number = 0.5 92 | time_mark_without_number = 0.1 93 | 94 | # variables de puntos susceptibles de ser F0 95 | voicing_threshold = 0.45 96 | octave_cost = 0.01 97 | octave_jump_cost = 0.35 98 | voiced_unvoiced_cost = 0.14 99 | 100 | if praatVersion < 5366 101 | exit Your Praat version ('praatVersion') is too old. Download the new one. 102 | endif 103 | 104 | if praatVersion < 5373 and macintosh = 1 105 | exit Your Praat version ('praatVersion') is too old. Download the new one. 106 | endif 107 | 108 | ############################ FORMULARIO ################################################################### 109 | 110 | form Create_pictures 111 | 112 | 113 | 114 | 115 | positive Dynamic_range 45 116 | boolean Draw_F0_curve 1 117 | boolean Draw_waveform yes 118 | 119 | boolean Draw_spectrogram 1 120 | boolean Draw_intensity 1 121 | boolean Draw_formants 0 122 | 123 | optionmenu Range 1 124 | option Define range automatically 125 | option Define range manually 126 | comment Do you want the f0min and f0max values to appear in the y axis? 127 | boolean f0min_f0max_marks 0 128 | positive Smooth 10 129 | boolean let_me_modify_my_pitch 0 130 | 131 | 132 | optionmenu Label_of_the_time_axis 8 133 | option No text 134 | option Tiempo (s) 135 | option Temps (s) 136 | option Time(s) 137 | option Tempo (s) 138 | option Zeit (s) 139 | option Denbora (s) 140 | option (s) 141 | 142 | optionmenu Label_of_the_frequency_axis 2 143 | option No text 144 | option F0 (Hz) 145 | option Frequency (Hz) 146 | option Frecuencia (Hz) 147 | option Freqüència (Hz) 148 | option Frequência (Hz) 149 | option Frequenza (Hz) 150 | option Frequenz (Hz) 151 | option Maiztasuna (Hz) 152 | option Fréquence (Hz) 153 | option (Hz) 154 | 155 | positive Picture_width 7 156 | 157 | comment Do you want to save the picture? 158 | boolean PNG 1 159 | sentence Pictures_folder /Users/weg/Desktop 160 | comment You can change more parametres: 161 | boolean Show_more_options 0 162 | endform 163 | 164 | 165 | 166 | ################# FORMULARIO OPCIONES ################################################################ 167 | 168 | if show_more_options = 1 or range = 2 or draw_F0_curve = 0 169 | beginPause ("Options") 170 | if range = 2 and draw_F0_curve = 1 171 | comment ("Introduce manually the range of the speaker.") 172 | sentence ("Manual_range", "50-250") 173 | endif 174 | 175 | if draw_spectrogram = 1 and show_more_options = 1 176 | comment ("Spectrogram settings") 177 | positive ("Spectrogram_maximum_frequency", 5000) 178 | endif 179 | 180 | if draw_spectrogram = 1 and show_more_options = 1 and draw_F0_curve = 1 and range = 2 181 | comment ("Spectrogram settings") 182 | positive ("Spectrogram_maximum_frequency", 5000) 183 | comment ("Introduce manually the range of the speaker.") 184 | sentence ("Manual_range", "50-250") 185 | endif 186 | 187 | if draw_F0_curve = 0 and draw_spectrogram = 1 188 | comment ("Spectrogram settings") 189 | positive ("Spectrogram_maximum_frequency", 5000) 190 | comment ("¿Every how many Hertzs do you want a frequency mark?") 191 | positive ("Frequency_marks_every", 2000) 192 | 193 | endif 194 | 195 | if show_more_options = 1 196 | comment ("¿Every how many seconds do you want a time mark in the waveform?") 197 | positive ("time_mark_with_number", 0.1) 198 | positive ("time_mark_without_number", 0.5 ) 199 | endif 200 | 201 | if draw_F0_curve = 1 and show_more_options = 1 202 | comment ("Find the F0 path") 203 | positive ("voicing_threshold", 0.45) 204 | positive ("octave_cost", 0.01) 205 | positive ("octave_jump_cost", 0.35) 206 | positive ("voiced_unvoiced_cost", 0.14) 207 | endif 208 | 209 | endPause ("OK", 1) 210 | endif 211 | 212 | 213 | 214 | ####################################################################################################### 215 | #variables de range 216 | if range = 2 217 | f0max = extractNumber (manual_range$, "-") 218 | f0max$ = "'f0max'" 219 | f0min$ = "'manual_range$'" - "'f0max$'" 220 | f0min$= "'f0min$'" - "-" 221 | f0min = 'f0min$' 222 | endif 223 | 224 | ################# EMPIEZA EL SCRIPT ######################################################### 225 | 226 | base$ = selected$ ("Sound") 227 | textgrid$ = selected$ ("TextGrid") 228 | mySound = selected("Sound") 229 | myText = selected("TextGrid") 230 | 231 | # Fuente de texto y color 232 | Times 233 | Font size: 14 234 | Line width: 1 235 | 236 | 237 | # Pictures waveform 238 | if draw_waveform = 1 239 | # Hace la ventana rosa para el oscilograma 240 | Viewport... 0 'picture_width' 0 2 241 | selectObject: mySound 242 | Grey 243 | Draw: 0, 0, 0, 0, "no", "curve" 244 | 245 | # Label x axis 246 | if label_of_the_time_axis <> 1 247 | if label_of_the_time_axis = 2 248 | label_of_the_time_axis$ = "Tiempo (s)" 249 | elsif label_of_the_time_axis = 3 250 | label_of_the_time_axis$ = "Temps (s)" 251 | elsif label_of_the_time_axis = 4 252 | label_of_the_time_axis$ = "Time(s)" 253 | elsif label_of_the_time_axis = 5 254 | label_of_the_time_axis$ = "Tempo(s)" 255 | elsif label_of_the_time_axis = 6 256 | label_of_the_time_axis$ = "Zeit (s)" 257 | elsif label_of_the_time_axis = 7 258 | label_of_the_time_axis$ = "Denbora(s)" 259 | elsif label_of_the_time_axis = 8 260 | label_of_the_time_axis$ = "(s)" 261 | endif 262 | #escribe el título del eje x (de tiempo) 263 | Text top... no 'label_of_the_time_axis$' 264 | endif 265 | 266 | #marks on time 267 | Marks top every... 1 'time_mark_without_number' no yes no 268 | Marks top every... 1 'time_mark_with_number' yes yes no 269 | 270 | 271 | endif 272 | 273 | 274 | 275 | if draw_spectrogram = 1 276 | # Creates objet Spectrogram 277 | selectObject: mySound 278 | mySpectrogram = To Spectrogram: 0.005, spectrogram_maximum_frequency, 0.002, 20, "Gaussian" 279 | 280 | # Crea la ventana de imagen para el espectrograma 281 | Viewport: 0, picture_width, 1, 4 282 | # Dibuja el espectrograma 283 | Black 284 | selectObject: mySpectrogram 285 | Paint: 0, 0, 0, 0, 100, "yes", dynamic_range, 6, 0, "no" 286 | Draw inner box 287 | 288 | Marks left every: 1, frequency_marks_every, "yes", "yes", "no" 289 | 290 | if label_of_the_frequency_axis <> 1 291 | if label_of_the_frequency_axis = 2 292 | label_of_the_frequency_axis$ = "Hz" 293 | elsif label_of_the_frequency_axis = 3 294 | label_of_the_frequency_axis$ = "Frequency (Hz)" 295 | elsif label_of_the_frequency_axis = 4 296 | label_of_the_frequency_axis$ = "Frecuencia (Hz)" 297 | elsif label_of_the_frequency_axis = 5 298 | label_of_the_frequency_axis$ = "Freqüència (Hz)" 299 | elsif label_of_the_frequency_axis = 6 300 | label_of_the_frequency_axis$ = "Frequência (Hz)" 301 | elsif label_of_the_frequency_axis = 7 302 | label_of_the_frequency_axis$ = "Frequenz (Hz)" 303 | elsif label_of_the_frequency_axis = 8 304 | label_of_the_frequency_axis$ = "Maiztasuna (Hz)" 305 | elsif label_of_the_frequency_axis = 9 306 | label_of_the_frequency_axis$ = "Fréquence (Hz)" 307 | elsif label_of_the_frequency_axis = 10 308 | label_of_the_frequency_axis$ = "(Hz)" 309 | endif 310 | #escribe el texto del eje y, si no hay curva de f0 311 | Text left... yes 'label_of_the_frequency_axis$' 312 | endif 313 | 314 | removeObject: mySpectrogram 315 | endif 316 | 317 | if draw_formants = 1 318 | select Sound 'base$' 319 | Viewport... 0 'picture_width' 1 4 320 | # creates formant objects 321 | myFormants = To Formant (burg): 0, 5, spectrogram_maximum_frequency, 0.025, 50 322 | 323 | Line width: 10 324 | White 325 | Speckle: 0, 0, spectrogram_maximum_frequency, 30, "no" 326 | Line width: 6 327 | Maroon 328 | Speckle: 0, 0, spectrogram_maximum_frequency, 30, "no" 329 | removeObject: myFormants 330 | endif 331 | 332 | 333 | if draw_intensity = 1 334 | # Crea la ventana de imagen para la intensidad 335 | if draw_waveform = 1 336 | # if we are drawing the waveform intensity is in the waveform 337 | Viewport: 0, picture_width, 0, 2 338 | else 339 | # if we don't have a vaweform we put the intensity over the spectrogram 340 | Viewport: 0, picture_width, 1, 4 341 | endif 342 | 343 | select Sound 'base$' 344 | myInt= To Intensity: 100, 0, "no" 345 | Line width: 4 346 | White 347 | Draw: 0, 0, 0, 0, "no" 348 | Line width: 4 349 | 350 | Yellow 351 | Draw: 0, 0, 0, 0, "no" 352 | Line width: 2 353 | 354 | if draw_F0_curve = 0 or draw_waveform = 1 355 | Marks right every: 1, 10, "yes", "yes", "no" 356 | Text right: "yes", "Int. (dB)" 357 | endif 358 | removeObject: myInt 359 | endif 360 | 361 | 362 | 363 | 364 | if draw_F0_curve = 1 365 | if range = 1 366 | Viewport: 0, picture_width, 1, 4 367 | 368 | # creates pitch object with default values 369 | select Sound 'base$' 370 | #removes fricatives almost-formants between 2000 and 3000 Hz, special for peninsular spanish sibilants 371 | soundBand= Filter (stop Hann band): 900, 20000, 100 372 | select Sound 'base$'_band 373 | pitch_gran_rango= To Pitch (filtered autocorrelation): 0, 50, 800, 15, "no", 0.03, 0.09, 0.5, 0.055, 0.35, 0.14 374 | 375 | Rename: "greatRange" 376 | #D. Hirst lines (getting pitch floor and ceiling) 377 | q1 = Get quantile... 0 0 0.25 Hertz 378 | q3 = Get quantile... 0 0 0.75 Hertz 379 | f0min = q1*0.75 380 | f0max = q3*1.8 381 | select Sound 'base$'_band 382 | #myNonSmoothedPitch= To Pitch... 0.005 'f0min' 'f0max' 383 | myNonSmoothedPitch= To Pitch (filtered autocorrelation): 0, f0min, f0max, 15, "no", 0.03, 0.09, 0.5, 0.055, 0.35, 0.14 384 | 385 | Rename: "nonSmoothedPitch" 386 | myPitch= Smooth... smooth 387 | Rename: "myPitch" 388 | if let_me_modify_my_pitch = 1 389 | pause Select your corrected pitch 390 | myPitch = selected ("Pitch") 391 | Rename: "myPitch" 392 | endif 393 | endif 394 | 395 | if range = 2 396 | # Crea objeto pitch 397 | select Sound 'base$' 398 | soundBand= Filter (stop Hann band): 900, 20000, 100 399 | #myNonSmoothedPitch = To Pitch (ac)... 0.005 'f0min' 15 no 0.03 'voicing_threshold' 'octave_cost' 'octave_jump_cost' 'voiced_unvoiced_cost' 'f0max' 400 | myNonSmoothedPitch= To Pitch (filtered autocorrelation): 0, f0min, f0max, 15, "no", 0.03, 0.09, 0.5, 0.055, 0.35, 0.14 401 | 402 | Rename: "nonSmoothedPitch" 403 | myPitch= Smooth: smooth 404 | Rename: "myPitch" 405 | if let_me_modify_my_pitch = 1 406 | pause Select your corrected pitch 407 | myPitch = selected ("Pitch") 408 | endif 409 | endif 410 | 411 | # Dibuja el pitch 412 | # Linea blanca de debajo 413 | Line width: 10 414 | White 415 | Viewport... 0 'picture_width' 1 4 416 | selectObject: myPitch 417 | Draw... 0 0 'f0min' 'f0max' no 418 | 419 | # Como una linea azul 420 | Line width: 6 421 | Cyan 422 | Draw: 0, 0, f0min, f0max, "no" 423 | 424 | 425 | # #Dibuja las s de F0. Eje y 426 | Line width... 1 427 | 428 | # Pone las marcas de f0 máxima y mínima si así se ha indicado en el formulario 429 | if f0min_f0max_marks = 1 430 | f0min$ = fixed$(f0min, 0) 431 | f0max$= fixed$(f0max, 0) 432 | f0min_redondeado = number (f0min$) 433 | f0max_redondeado = number (f0max$) 434 | f0max_redondeado = f0max_redondeado/10 435 | f0min_redondeado = f0min_redondeado/10 436 | f0max_redondeado$ = fixed$(f0max_redondeado, 0) 437 | f0max_redondeado = number (f0max_redondeado$) 438 | f0min_redondeado$ = fixed$(f0min_redondeado, 0) 439 | f0min_redondeado = number (f0min_redondeado$) 440 | f0min_redondeado = f0min_redondeado * 10 441 | f0max_redondeado = f0max_redondeado * 10 442 | One mark right... f0min_redondeado yes no no 443 | One mark right... f0max_redondeado yes no no 444 | 445 | #One mark right... 'f0max' yes no no 446 | #One mark right... 'f0min' yes no no 447 | endif 448 | 449 | 450 | # Determines pitch marks (each 50, 100 or 150Hz) depending on speakers range 451 | speakers_range = f0max - f0min 452 | 453 | 454 | if speakers_range >= 500 455 | intervalo_entre_marcas = 150 456 | elsif speakers_range >= 300 457 | intervalo_entre_marcas = 100 458 | elsif speakers_range < 300 459 | intervalo_entre_marcas = 50 460 | endif 461 | 462 | numero_de_marcasf0 = (speakers_range/intervalo_entre_marcas)+ 1 463 | 464 | # Determines first mark in the spectrogram depending on f0 min introduced by the user 465 | 466 | if f0min >= 250 467 | marca = 250 468 | elsif f0min >= 200 469 | marca = 200 470 | elsif f0min >= 150 471 | marca = 150 472 | elsif f0min >= 100 473 | marca = 100 474 | elsif f0min >= 50 475 | marca = 50 476 | elsif f0min < 50 477 | marca = 0 478 | endif 479 | 480 | # writes F0 in Hz according to parameters 481 | for i to numero_de_marcasf0 482 | marca = marca + intervalo_entre_marcas 483 | marca$ = "'marca'" 484 | if marca <= f0max 485 | do ("One mark right...", 'marca', "yes", "yes", "no", "'marca$'") 486 | endif 487 | endfor 488 | 489 | 490 | #draws black box 491 | Line width: 1 492 | Draw inner box 493 | 494 | Cyan 495 | 496 | #Determines title of x axis 497 | if label_of_the_frequency_axis <> 1 498 | if label_of_the_frequency_axis = 2 499 | label_of_the_frequency_axis$ = "F0 (Hz)" 500 | endif 501 | if label_of_the_frequency_axis = 3 502 | label_of_the_frequency_axis$ = "Frequency (Hz)" 503 | elsif label_of_the_frequency_axis = 4 504 | label_of_the_frequency_axis$ = "Frecuencia (Hz)" 505 | elsif label_of_the_frequency_axis = 5 506 | label_of_the_frequency_axis$ = "Freqüència (Hz)" 507 | elsif label_of_the_frequency_axis = 6 508 | label_of_the_frequency_axis$ = "Frequência (Hz)" 509 | elsif label_of_the_frequency_axis = 7 510 | label_of_the_frequency_axis$ = "Frequenz (Hz)" 511 | elsif label_of_the_frequency_axis = 8 512 | label_of_the_frequency_axis$ = "Maiztasuna (Hz)" 513 | elsif label_of_the_frequency_axis = 9 514 | label_of_the_frequency_axis$ = "Fréquence (Hz)" 515 | elsif label_of_the_frequency_axis = 10 516 | label_of_the_frequency_axis$ = "(Hz)" 517 | endif 518 | #writes titles y axis 519 | Text right... yes 'label_of_the_frequency_axis$' 520 | endif 521 | 522 | removeObject: myPitch, soundBand 523 | 524 | if range=1 525 | removeObject: pitch_gran_rango, myNonSmoothedPitch 526 | endif 527 | 528 | 529 | if range=2 530 | removeObject: myNonSmoothedPitch 531 | endif 532 | 533 | endif 534 | 535 | 536 | 537 | 538 | 539 | ####################### DIBUJA EL TEXTGRID #################################### 540 | selectObject: myText 541 | Convert to backslash trigraphs 542 | 543 | ## deals with unicode characters 544 | numberOfTiers = Get number of tiers 545 | 546 | # EXTRA % does not work as unicode, so a rough replacement is done 547 | if numberOfTiers >= 1 548 | for tier to numberOfTiers 549 | selectObject: myText 550 | isInterval= Is interval tier: tier 551 | if isInterval= 1 552 | nIntervals = Get number of intervals: tier 553 | Replace interval text: tier, 0, nIntervals, "%", "\% ", "Literals" 554 | Replace interval text: tier, 0, nIntervals, "\\", "\", "Literals" 555 | endif 556 | if isInterval=0 557 | nPoints = Get number of points: tier 558 | Replace point text: tier, 0, nPoints, "%", "\% ", "Literals" 559 | Replace point text: tier, 0, nPoints, "\\", "\", "Literals" 560 | endif 561 | endfor 562 | else 563 | exitScript: "No tiers in your TextGrid: " + base$ 564 | endif 565 | 566 | 567 | #Defines de size of the box depending on the number of tiers in the textgrid 568 | cajatextgrid = (4 + 0.5 * 'numberOfTiers') - 0.02 * 'numberOfTiers' 569 | 570 | 571 | # selects pink window for the textwrif 572 | Viewport... 0 'picture_width' 1 'cajatextgrid' 573 | 574 | 575 | # Dibuja el TextGrid 576 | Grey 577 | select TextGrid 'base$' 578 | Draw... 0 0 yes yes no 579 | 580 | 581 | else 582 | pauseScript: "There is no TextGrid for the Sound " + base$ 583 | cajatextgrid = 4 584 | 585 | endif 586 | 587 | 588 | if draw_waveform=1 589 | Line width: 1 590 | Grey 591 | Viewport... 0 'picture_width' 0 'cajatextgrid' 592 | else 593 | Grey 594 | Viewport... 0 'picture_width' 1 'cajatextgrid' 595 | endif 596 | Draw inner box 597 | 598 | else 599 | # If the textgrid is not drawn i select the viewport again with the whole picture 600 | Line width: 1 601 | 602 | if draw_waveform=1 603 | Grey 604 | Viewport... 0 'picture_width' 0 4 605 | else 606 | Grey 607 | Viewport... 0 'picture_width' 1 4 608 | endif 609 | 610 | Draw inner box 611 | endif 612 | 613 | ############################# GUARDA LA IMAGEN ############################## 614 | 615 | 616 | if pNG = 1 617 | Save as 300-dpi PNG file: pictures_folder$ + "/" + base$ + ".png" 618 | # borra la caja de picture si no dibujaría encima 619 | Erase all 620 | echo Picture saved in 'pictures_folder$' 621 | endif 622 | 623 | 624 | selectObject: mySound, myText 625 | 626 | -------------------------------------------------------------------------------- /create_pictures.praat: -------------------------------------------------------------------------------- 1 | ############################################################################################################################################################################################ 2 | # 3 | # create_pictures-with-tiers.praat (v.6 -2022-) 4 | # Wendy Elvira-García 5 | # Laboratori de Fonètica (Universitat de Barcelona) 6 | # 7 | # DESCRIPTION 8 | # This script creates and saves pictures (PNG, PDF, wmf, eps, PraatPic) of all the Sound and optionally a matching TextGrid file it finds in a folder. 9 | # The pictures contain a waveform (optional), a spectrogram (optional), the F0 track (optional) the intensity track (optional), formant track and the content of the tiers of the TextGrid associated with the sound file (optional) and only if it finds one. 10 | # 11 | # The script is designed to carry out some operations automatically: 12 | # 13 | # 1) If you are drawing a TextGrid, it recognizes automatically the number of tiers in EACH textgrid and draws the picture consequently (i.e. in the picture there will be 14 | # no unnecessary white space between the tiers and the spectrogram). 15 | # 2) It converts the TextGrid to backslash trigraphs before drawing, so you won't have problems plotting symbols like % or phonetic symbols 16 | # 3) It detects automatically the F0 range of the picture of EACH sentence (unless you choose to specify it manually). 17 | # 4)In order to correct those cases in which Praat detects F0 in fricatives (what Boersma calls "to hallucinate pitches")the script gets 18 | # the pitch from a filtered sound in which all frequencies beyond 1000Hz have been cancelled. In addition, it uses Hirst's code "pitch in two steps" to find the speaker range 19 | # 5) It establishes automatically the number of marks on the y-axis and their placement. It places the first mark at the lowest multiple of 50 Hz within the range 20 | # of the picture (e.g. at 50 Hz, or 100 Hz, or 150 Hz...). The following marks are placed every 50/100/150 Hz (depending on the range of the utterance). 21 | # 22 | # In the INSTRUCTIONS section you will find details about the other characteristics and options of the script (e.g changing the dynamic range, 23 | # choosing the level of smoothness in the F0 track, changing the axis' names, choosing the speaker's range of F0...) 24 | # 25 | # 26 | # 27 | # INSTRUCTIONS 28 | # 0. Before you start: 29 | # - Check that your .wav filename does not contain white spaces. 30 | # - If you want to draw TextGrids, create the TextGrids with the same name as the sound they are made for. Save them in a folder. 31 | # 32 | # 1. Open the script (Open/Read from file...), click Run in the upper menu and Run again. 33 | # 2. Set the parameters. 34 | # a) The 3 first fields are for the folders where you have your files. In the first field, write the name of the folder where you have your sound files. 35 | # In the second field, write the name of the folder where you have your Textgrids. In the third field, write the name of the folder where 36 | # you want the pictures to be saved. Use / in mac and \ in windows 37 | # b) By changing the dynamic range you can make your spectrograms look 'cleaner'. The lowest it is, the lighter the spectrogram looks. 38 | # c) Choose what do you want to draw, waveform, spectrogram, and intensity. And whether you want to draw the F0 curve or not. The F0 curve will be written twice, once in white and once in thinner black (Welby 2003). 39 | # d) Then specify if you want the F0 range to be defined automatically or manually. If you choose to set it manually, 40 | # in the next window you'll be asked to define the F0 minimum and F0 maximum. 41 | # e) Choose if you want the F0 minimum and F0 maximum marks to appear on the y-axis (if you place them, they might overlap with other marks). 42 | # Note that the F0 minimum and F0 maximum marks are placed at 'rounded' values, which means that 377.8 Hz is rounded to 380 Hz and 51.2 Hz is rounded to 50 Hz. 43 | # f) Decide how much you want the F0 curve to be smoothed. In this field, you need to enter the bandwidth (in Hertz). If you want a 44 | # very smoothed curve, you should choose a smaller bandwidth (e.g. 10), whereas if you want a less smoothed curve you should choose a bigger bandwidth (e.g. 50). 45 | # Don't write 0 in here, because your curve would become plain. 46 | # g)In the next two choice menus, you can choose the label of the axes (in different languages). You can also decide not to label either or both of them. 47 | # h) You can change the picture width. 48 | # i) Mark the formats in which you want to save the pictures. Notice that PDF will only run if you are working 49 | # on a Mac and wmf is only for Windows. PNG for Windows and presumably Linux. 50 | # j)Mark whether you want more options or not. (See below for details) 51 | # Click OK 52 | # 53 | # MORE OPTIONS WINDOW 54 | # If you chose the more options button or if you chose to set the speaker's range manually, a new window will appear. In this window you can: 55 | # a) Set the F0 range in the picture. You must write the numbers separated by a hyphen. This field will only appear if you chose "Set the range manually" 56 | # in the previous form. 57 | # b) Choose the spectrogram range. This is by default from 0 to 5000Hz. 58 | # c) If you have chosen not to draw the F0 curve, you can select here how many marks of frequency you want in the spectrogram. 59 | # You'll be asked every how many Hz you want a mark. 60 | # d) Change the time marks of the x-axis. By default, there is a mark without a number at every 0.2 seconds and a mark with a number at every 0.5 (the number appears 61 | # written above the mark.) 62 | # e) If you are drawing the f0 curve and you've chosen "Show more options", you can choose here how do you want Praat to select the better candidates to be F0. 63 | # The script runs with the autocorrelation method (Boersma, 1993) which is optimized for human intonation research, so if you are working with speech, 64 | # You don't need to change anything. 65 | # Here you'll be asked for the octave cost, octave jump cost, the voiced/unvoiced cost and the voicing_threshold. 66 | # 67 | # 68 | # 69 | # Click OK (the Revert button goes back to the Standards of the form) 70 | # 71 | # 3. Now search your pictures, they have to be in the folder you specified in the first window (the form). 72 | # 73 | # 74 | # 75 | # CREDITS 76 | # Feedback is always welcome, please if you notice any bugs or come up with anything that can improve this script, let me know! 77 | # 78 | # Wendy Elvira-García 79 | # wendyelviragarcia@gmail.com // www.wendyelvira.ga 80 | # first version: october 2013 81 | # 82 | # Citation: Elvira García, Wendy (2022). Create pictures with tiers v.6. Praat script. (Retrieved from https://github.com/wendyelviragarcia/create_pictures) 83 | # 84 | # The first version of this script was inspired by: 85 | # draw-waveform-sgram-f0.praat 86 | # Pauline Welby (2003) with the modifications made by Paolo Roseano (2011) 87 | 88 | # LICENSE 89 | # Copyright (C) 2022 Wendy Elvira 90 | 91 | # This program is free software; you can redistribute it and/or 92 | # modify it under the terms of the GNU General Public License 93 | # as published by the Free Software Foundation; either version 3 94 | # of the License, or (at your option) any later version. 95 | 96 | # This program is distributed in the hope that it will be useful, 97 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 98 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 99 | # GNU General Public License for more details. 100 | 101 | # You can find the terms of the GNU General Public License here 102 | # http://www.gnu.org/licenses/gpl-3.0.en.html 103 | # 104 | ################################################################################################################################### 105 | # FIXED VARIBLES 106 | 107 | spectrogram_maximum_frequency = 5000 108 | let_me_modify_my_pitch = 0 109 | frequency_marks_every= 1000 110 | 111 | #variables para el tiempo cada (ms) 112 | time_mark_with_number = 0.5 113 | time_mark_without_number = 0.1 114 | 115 | # variables de puntos susceptibles de ser F0 116 | voicing_threshold = 0.45 117 | octave_cost = 0.01 118 | octave_jump_cost = 0.35 119 | voiced_unvoiced_cost = 0.14 120 | 121 | if praatVersion < 5366 122 | exit Your Praat version ('praatVersion') is too old. Download the new one. 123 | endif 124 | 125 | if praatVersion < 5373 and macintosh = 1 126 | exit Your Praat version ('praatVersion') is too old. Download the new one. 127 | endif 128 | 129 | ############################ FORM ################################################################### 130 | 131 | form Create_pictures 132 | comment Where are your files? 133 | sentence Sounds_folder /Users/weg/Desktop/test 134 | sentence TextGrids_folder /Users/weg/Desktop/test 135 | sentence Pictures_folder /Users/weg/Desktop/test 136 | boolean Draw_waveform yes 137 | boolean Draw_spectrogram 1 138 | boolean Draw_intensity 1 139 | boolean Draw_formants 0 140 | boolean Draw_TextGrid 1 141 | boolean Draw_pulses 1 142 | 143 | positive Dynamic_range 45 144 | boolean Draw_F0_curve no 145 | optionmenu Range 1 146 | option Define range automatically 147 | option Define range manually 148 | comment Do you want the f0min and f0max values to appear in the y axis? 149 | boolean f0min_f0max_marks 0 150 | positive Smooth 10 151 | 152 | 153 | optionmenu Label_of_the_time_axis 8 154 | option No text 155 | option Tiempo (s) 156 | option Temps (s) 157 | option Time(s) 158 | option Tempo (s) 159 | option Zeit (s) 160 | option Denbora (s) 161 | option (s) 162 | 163 | optionmenu Label_of_the_frequency_axis 2 164 | option No text 165 | option F0 (Hz) 166 | option Frequency (Hz) 167 | option Frecuencia (Hz) 168 | option Freqüència (Hz) 169 | option Frequência (Hz) 170 | option Frequenza (Hz) 171 | option Frequenz (Hz) 172 | option Maiztasuna (Hz) 173 | option Fréquence (Hz) 174 | option (Hz) 175 | 176 | positive Picture_width 7 177 | 178 | comment In which format(s) do you want the picture? 179 | optionmenu Picture_Format 1 180 | option PNG_300_dpi 181 | option PNG_600_dpi 182 | option PDF_(for_Mac_and_Linux) 183 | option Windows_Media_File_(.wmf_(Windows_only)) 184 | option EPS 185 | option praatPic 186 | 187 | comment You can change more parametres: 188 | boolean Show_more_options 0 189 | endform 190 | 191 | 192 | 193 | ################# FORM OPTIONS ############################### 194 | 195 | if show_more_options = 1 or range = 2 or draw_F0_curve = 0 196 | beginPause ("Options") 197 | if range = 2 and draw_F0_curve = 1 198 | comment ("Introduce manually the range of the speaker.") 199 | sentence ("Manual_range", "50-250") 200 | endif 201 | 202 | if draw_spectrogram = 1 and show_more_options = 1 and draw_F0_curve = 1 203 | comment ("Spectrogram settings") 204 | positive ("Spectrogram_maximum_frequency", 5000) 205 | endif 206 | 207 | if draw_F0_curve = 0 and draw_spectrogram = 1 208 | comment ("Spectrogram settings") 209 | positive ("Spectrogram_maximum_frequency", 5000) 210 | comment ("¿Every how many Hertzs do you want a frequency mark?") 211 | positive ("Frequency_marks_every", 2000) 212 | 213 | endif 214 | 215 | if show_more_options = 1 216 | comment ("¿Every how many seconds do you want a time mark in the waveform?") 217 | positive ("time_mark_with_number", 0.1) 218 | positive ("time_mark_without_number", 0.5 ) 219 | endif 220 | 221 | if draw_F0_curve = 1 and show_more_options = 1 222 | comment ("Find the F0 path") 223 | positive ("voicing_threshold", 0.45) 224 | positive ("octave_cost", 0.01) 225 | positive ("octave_jump_cost", 0.35) 226 | positive ("voiced_unvoiced_cost", 0.14) 227 | endif 228 | 229 | endPause ("OK", 1) 230 | endif 231 | 232 | 233 | 234 | ######################################################################## 235 | # range variables 236 | if range = 2 237 | f0max = extractNumber (manual_range$, "-") 238 | f0max$ = "'f0max'" 239 | f0min$ = "'manual_range$'" - "'f0max$'" 240 | f0min$= "'f0min$'" - "-" 241 | f0min = 'f0min$' 242 | endif 243 | 244 | ################# SCRIPT BEGGINS ##################### 245 | 246 | # creates list of every file in folder 247 | myFileList= Create Strings as file list: "mywavlist", sounds_folder$ + "/" + "*" 248 | numberOfFiles = Get number of strings 249 | 250 | for stri to numberOfFiles 251 | filename$ = Get string: stri 252 | if (right$(filename$, 4) <> ".wav") and (right$(filename$, 4) <> ".WAV") 253 | Remove string: stri 254 | stri= stri-1 255 | numberOfFiles= numberOfFiles-1 256 | endif 257 | endfor 258 | 259 | numberOfFiles = Get number of strings 260 | if numberOfFiles = 0 261 | exitScript: "There are no .wav or .WAV files in folder" + sounds_folder$ 262 | endif 263 | 264 | Erase all 265 | 266 | #loop beggins, the following actions will be performed for all wavs in the folder 267 | for ifile to numberOfFiles 268 | #selects the file number x from the object Strings mywavlist 269 | select Strings mywavlist 270 | fileName$ = Get string: ifile 271 | spaces = index (fileName$, " ") 272 | 273 | if spaces <> 0 274 | exit "Filenames cannot contain spaces" 275 | endif 276 | 277 | base$ = fileName$ - ".wav" 278 | base$ = base$ - ".WAV" 279 | 280 | # Reads Sound 281 | mySound = Read from file: sounds_folder$+ "/" + fileName$ 282 | 283 | 284 | 285 | # Fuente de texto y color 286 | Times 287 | Font size: 14 288 | Line width: 1 289 | 290 | 291 | # Pictures waveform 292 | if draw_waveform = 1 293 | # Hace la ventana rosa para el oscilograma 294 | Viewport... 0 'picture_width' 0 2 295 | selectObject: mySound 296 | Grey 297 | Draw: 0, 0, 0, 0, "no", "curve" 298 | 299 | # Label x axis 300 | if label_of_the_time_axis <> 1 301 | if label_of_the_time_axis = 2 302 | label_of_the_time_axis$ = "Tiempo (s)" 303 | elsif label_of_the_time_axis = 3 304 | label_of_the_time_axis$ = "Temps (s)" 305 | elsif label_of_the_time_axis = 4 306 | label_of_the_time_axis$ = "Time(s)" 307 | elsif label_of_the_time_axis = 5 308 | label_of_the_time_axis$ = "Tempo(s)" 309 | elsif label_of_the_time_axis = 6 310 | label_of_the_time_axis$ = "Zeit (s)" 311 | elsif label_of_the_time_axis = 7 312 | label_of_the_time_axis$ = "Denbora(s)" 313 | elsif label_of_the_time_axis = 8 314 | label_of_the_time_axis$ = "(s)" 315 | endif 316 | #escribe el título del eje x (de tiempo) 317 | Text top... no 'label_of_the_time_axis$' 318 | endif 319 | 320 | #marks on time 321 | Marks top every... 1 'time_mark_without_number' no yes no 322 | Marks top every... 1 'time_mark_with_number' yes yes no 323 | 324 | 325 | endif 326 | 327 | if draw_pulses = 1 328 | if draw_waveform = 1 329 | Viewport... 0 'picture_width' 0 2 330 | selectObject: mySound 331 | myPoints= To PointProcess (periodic, cc): 75, 600 332 | Navy 333 | Draw: 0, 0, "no" 334 | removeObject: myPoints 335 | else 336 | beginPause: "Pause" 337 | comment: "You need a waveform to draw pulses," 338 | comment: "I'm not drawing the pulses but I'll do the rest." 339 | clicked = endPause: "Proceed", 1 340 | endif 341 | endif 342 | 343 | 344 | 345 | if draw_spectrogram = 1 346 | # Creates objet Spectrogram 347 | selectObject: mySound 348 | mySpectrogram = To Spectrogram: 0.005, spectrogram_maximum_frequency, 0.002, 20, "Gaussian" 349 | 350 | # Crea la ventana de imagen para el espectrograma 351 | Viewport: 0, picture_width, 1, 4 352 | # Dibuja el espectrograma 353 | Black 354 | selectObject: mySpectrogram 355 | Paint: 0, 0, 0, 0, 100, "yes", dynamic_range, 6, 0, "no" 356 | Draw inner box 357 | 358 | Marks left every: 1, frequency_marks_every, "yes", "yes", "no" 359 | 360 | if label_of_the_frequency_axis <> 1 361 | if label_of_the_frequency_axis = 2 362 | label_of_the_frequency_axis$ = "Hz" 363 | elsif label_of_the_frequency_axis = 3 364 | label_of_the_frequency_axis$ = "Frequency (Hz)" 365 | elsif label_of_the_frequency_axis = 4 366 | label_of_the_frequency_axis$ = "Frecuencia (Hz)" 367 | elsif label_of_the_frequency_axis = 5 368 | label_of_the_frequency_axis$ = "Freqüència (Hz)" 369 | elsif label_of_the_frequency_axis = 6 370 | label_of_the_frequency_axis$ = "Frequência (Hz)" 371 | elsif label_of_the_frequency_axis = 7 372 | label_of_the_frequency_axis$ = "Frequenz (Hz)" 373 | elsif label_of_the_frequency_axis = 8 374 | label_of_the_frequency_axis$ = "Maiztasuna (Hz)" 375 | elsif label_of_the_frequency_axis = 9 376 | label_of_the_frequency_axis$ = "Fréquence (Hz)" 377 | elsif label_of_the_frequency_axis = 10 378 | label_of_the_frequency_axis$ = "(Hz)" 379 | endif 380 | #escribe el texto del eje y, si no hay curva de f0 381 | Text left... yes 'label_of_the_frequency_axis$' 382 | endif 383 | 384 | removeObject: mySpectrogram 385 | endif 386 | 387 | 388 | 389 | 390 | 391 | 392 | if draw_intensity = 1 393 | # Crea la ventana de imagen para la intensidad 394 | if draw_waveform = 1 395 | # if we are drawing the waveform intensity is in the waveform 396 | Viewport: 0, picture_width, 0, 2 397 | else 398 | # if we don't have a vaweform we put the intensity over the spectrogram 399 | Viewport: 0, picture_width, 1, 4 400 | endif 401 | 402 | select Sound 'base$' 403 | myInt= To Intensity: 100, 0, "no" 404 | Line width: 4 405 | White 406 | Draw: 0, 0, 0, 0, "no" 407 | Line width: 4 408 | 409 | Olive 410 | Draw: 0, 0, 0, 0, "no" 411 | Line width: 2 412 | 413 | if draw_F0_curve = 0 or draw_waveform = 1 414 | Marks right every: 1, 10, "yes", "yes", "no" 415 | Text right: "yes", "Int. (dB)" 416 | endif 417 | removeObject: myInt 418 | endif 419 | 420 | if draw_F0_curve = 1 421 | if range = 1 422 | Viewport: 0, picture_width, 1, 4 423 | 424 | # creates pitch object with default values 425 | select Sound 'base$' 426 | #removes fricatives almost-formants between 2000 and 3000 Hz, special for peninsular spanish sibilants 427 | soundBand= Filter (stop Hann band): 900, 20000, 100 428 | select Sound 'base$'_band 429 | pitch_gran_rango= To Pitch (ac)... 0.005 50 15 no 0.03 'voicing_threshold' 'octave_cost' 'octave_jump_cost' 'voiced_unvoiced_cost' 650 430 | Rename: "greatRange" 431 | #D. Hirst lines (getting pitch floor and ceiling) 432 | q1 = Get quantile... 0 0 0.25 Hertz 433 | q3 = Get quantile... 0 0 0.75 Hertz 434 | f0min = q1*0.75 435 | f0max = q3*1.8 436 | select Sound 'base$'_band 437 | myNonSmoothedPitch= To Pitch... 0.005 'f0min' 'f0max' 438 | Rename: "nonSmoothedPitch" 439 | myPitch= Smooth... smooth 440 | Rename: "myPitch" 441 | if let_me_modify_my_pitch=1 442 | pause Select your corrected pitch 443 | myPitch = selected ("Pitch") 444 | Rename: "myPitch" 445 | endif 446 | endif 447 | 448 | if range = 2 449 | # Crea objeto pitch 450 | select Sound 'base$' 451 | soundBand= Filter (stop Hann band): 900, 20000, 100 452 | myNonSmoothedPitch = To Pitch (ac)... 0.005 'f0min' 15 no 0.03 'voicing_threshold' 'octave_cost' 'octave_jump_cost' 'voiced_unvoiced_cost' 'f0max' 453 | Rename: "nonSmoothedPitch" 454 | myPitch= Smooth: smooth 455 | Rename: "myPitch" 456 | if let_me_modify_my_pitch = 1 457 | pause Select your corrected pitch 458 | myPitch = selected ("Pitch") 459 | endif 460 | endif 461 | 462 | # Dibuja el pitch 463 | # Linea blanca de debajo 464 | Line width: 10 465 | White 466 | Viewport... 0 'picture_width' 1 4 467 | selectObject: myPitch 468 | Draw... 0 0 'f0min' 'f0max' no 469 | 470 | # Como una linea azul 471 | Line width: 6 472 | Cyan 473 | Draw: 0, 0, f0min, f0max, "no" 474 | 475 | 476 | # #Dibuja las s de F0. Eje y 477 | Line width... 1 478 | 479 | # Pone las marcas de f0 máxima y mínima si así se ha indicado en el formulario 480 | if f0min_f0max_marks = 1 481 | f0min$ = fixed$(f0min, 0) 482 | f0max$= fixed$(f0max, 0) 483 | f0min_redondeado = number (f0min$) 484 | f0max_redondeado = number (f0max$) 485 | f0max_redondeado = f0max_redondeado/10 486 | f0min_redondeado = f0min_redondeado/10 487 | f0max_redondeado$ = fixed$(f0max_redondeado, 0) 488 | f0max_redondeado = number (f0max_redondeado$) 489 | f0min_redondeado$ = fixed$(f0min_redondeado, 0) 490 | f0min_redondeado = number (f0min_redondeado$) 491 | f0min_redondeado = f0min_redondeado * 10 492 | f0max_redondeado = f0max_redondeado * 10 493 | One mark right... f0min_redondeado yes no no 494 | One mark right... f0max_redondeado yes no no 495 | 496 | #One mark right... 'f0max' yes no no 497 | #One mark right... 'f0min' yes no no 498 | endif 499 | 500 | 501 | # Determines pitch marks (each 50, 100 or 150Hz) depending on speakers range 502 | speakers_range = f0max - f0min 503 | 504 | 505 | if speakers_range >= 500 506 | intervalo_entre_marcas = 150 507 | elsif speakers_range >= 300 508 | intervalo_entre_marcas = 100 509 | elsif speakers_range < 300 510 | intervalo_entre_marcas = 50 511 | endif 512 | 513 | numero_de_marcasf0 = (speakers_range/intervalo_entre_marcas)+ 1 514 | 515 | # Determines first mark in the spectrogram depending on f0 min introduced by the user 516 | 517 | if f0min >= 250 518 | marca = 250 519 | elsif f0min >= 200 520 | marca = 200 521 | elsif f0min >= 150 522 | marca = 150 523 | elsif f0min >= 100 524 | marca = 100 525 | elsif f0min >= 50 526 | marca = 50 527 | elsif f0min < 50 528 | marca = 0 529 | endif 530 | 531 | # writes F0 in Hz according to parameters 532 | for i to numero_de_marcasf0 533 | marca = marca + intervalo_entre_marcas 534 | marca$ = "'marca'" 535 | if marca <= f0max 536 | do ("One mark right...", 'marca', "yes", "yes", "no", "'marca$'") 537 | endif 538 | endfor 539 | 540 | 541 | #draws black box 542 | Line width: 1 543 | Draw inner box 544 | 545 | Cyan 546 | 547 | #Determines title of x axis 548 | if label_of_the_frequency_axis <> 1 549 | if label_of_the_frequency_axis = 2 550 | label_of_the_frequency_axis$ = "F0 (Hz)" 551 | endif 552 | if label_of_the_frequency_axis = 3 553 | label_of_the_frequency_axis$ = "Frequency (Hz)" 554 | elsif label_of_the_frequency_axis = 4 555 | label_of_the_frequency_axis$ = "Frecuencia (Hz)" 556 | elsif label_of_the_frequency_axis = 5 557 | label_of_the_frequency_axis$ = "Freqüència (Hz)" 558 | elsif label_of_the_frequency_axis = 6 559 | label_of_the_frequency_axis$ = "Frequência (Hz)" 560 | elsif label_of_the_frequency_axis = 7 561 | label_of_the_frequency_axis$ = "Frequenz (Hz)" 562 | elsif label_of_the_frequency_axis = 8 563 | label_of_the_frequency_axis$ = "Maiztasuna (Hz)" 564 | elsif label_of_the_frequency_axis = 9 565 | label_of_the_frequency_axis$ = "Fréquence (Hz)" 566 | elsif label_of_the_frequency_axis = 10 567 | label_of_the_frequency_axis$ = "(Hz)" 568 | endif 569 | #writes titles y axis 570 | Text right... yes 'label_of_the_frequency_axis$' 571 | endif 572 | removeObject: myNonSmoothedPitch,pitch_gran_rango, myPitch, soundBand 573 | 574 | endif 575 | 576 | if draw_formants = 1 577 | select Sound 'base$' 578 | Viewport... 0 'picture_width' 1 4 579 | # creates formant objects 580 | myFormants = To Formant (burg): 0, 5, spectrogram_maximum_frequency, 0.025, 50 581 | 582 | Line width: 10 583 | White 584 | Speckle: 0, 0, spectrogram_maximum_frequency, 30, "no" 585 | Line width: 6 586 | Maroon 587 | Speckle: 0, 0, spectrogram_maximum_frequency, 30, "no" 588 | removeObject: myFormants 589 | endif 590 | 591 | 592 | 593 | 594 | 595 | 596 | ####################### DIBUJA EL TEXTGRID #################################### 597 | if draw_TextGrid = 1 598 | Line width: 1 599 | 600 | if fileReadable (textGrids_folder$ + "/" + base$ +".TextGrid" ) 601 | myText = Read from file: textGrids_folder$ +"/"+ base$+".TextGrid" 602 | Convert to backslash trigraphs 603 | 604 | ## deals with unicode characters 605 | numberOfTiers = Get number of tiers 606 | 607 | # EXTRA % does not work as unicode, so a rough replacement is done 608 | if numberOfTiers >= 1 609 | for tier to numberOfTiers 610 | selectObject: myText 611 | isInterval= Is interval tier: tier 612 | if isInterval= 1 613 | nIntervals = Get number of intervals: tier 614 | Replace interval text: tier, 0, nIntervals, "%", "\% ", "Literals" 615 | Replace interval text: tier, 0, nIntervals, "\\", "\", "Literals" 616 | endif 617 | if isInterval=0 618 | nPoints = Get number of points: tier 619 | Replace point text: tier, 0, nPoints, "%", "\% ", "Literals" 620 | Replace point text: tier, 0, nPoints, "\\", "\", "Literals" 621 | endif 622 | endfor 623 | else 624 | exitScript: "No tiers in your TextGrid: " + base$ 625 | endif 626 | 627 | 628 | #Defines de size of the box depending on the number of tiers in the textgrid 629 | cajatextgrid = (4 + 0.5 * 'numberOfTiers') - 0.02 * 'numberOfTiers' 630 | 631 | 632 | # selects pink window for the textwrif 633 | Viewport... 0 'picture_width' 1 'cajatextgrid' 634 | 635 | 636 | # Dibuja el TextGrid 637 | Grey 638 | select TextGrid 'base$' 639 | Draw... 0 0 yes yes no 640 | 641 | 642 | else 643 | pauseScript: "There is no TextGrid for the Sound " + base$ 644 | cajatextgrid = 4 645 | 646 | endif 647 | 648 | 649 | 650 | # selects window for box 651 | if draw_waveform=1 652 | Line width: 1 653 | Grey 654 | Viewport... 0 'picture_width' 0 'cajatextgrid' 655 | else 656 | Grey 657 | Viewport... 0 'picture_width' 1 'cajatextgrid' 658 | endif 659 | Draw inner box 660 | 661 | else 662 | # If the textgrid is not drawn i select the viewport again with the whole picture 663 | 664 | if draw_waveform=1 665 | Grey 666 | Viewport... 0 'picture_width' 0 4 667 | else 668 | Grey 669 | Viewport... 0 'picture_width' 1 4 670 | endif 671 | 672 | Draw inner box 673 | endif 674 | ############################# SAVES IMAGE ############################## 675 | 676 | if picture_Format = 1 677 | Save as 300-dpi PNG file: pictures_folder$ + "/" + base$ + ".png" 678 | endif 679 | 680 | if picture_Format = 2 681 | Save as 600-dpi PNG file: pictures_folder$ + "/" + base$ + ".png" 682 | endif 683 | 684 | if picture_Format = 3 685 | Save as PDF file: pictures_folder$ +"/"+ base$ + ".pdf" 686 | endif 687 | 688 | if picture_Format = 4 689 | Write to Windows metafile: pictures_folder$+"/"+base$+".wmf" 690 | endif 691 | 692 | if picture_Format = 5 693 | Write to EPS file: pictures_folder$ +"/"+ base$ ".eps" 694 | endif 695 | 696 | if picture_Format = 6 697 | Write to praat picture file: pictures_folder$ + "/"+ base$ +".praapic" 698 | endif 699 | 700 | # erases the picture window for the next figure 701 | Erase all 702 | 703 | # cleaning objects 704 | select all 705 | minus Strings mywavlist 706 | Remove 707 | 708 | endfor 709 | 710 | ################################################################ 711 | # AFTER LOOP ACTIONS 712 | ################################################################ 713 | 714 | # final cleaning 715 | select Strings mywavlist 716 | Remove 717 | numberOfprocessed = ifile-1 718 | numberOfprocessed$ = fixed$(numberOfprocessed,0) 719 | writeInfoLine: numberOfprocessed$ + " pictures have been created." 720 | appendInfoLine: "The picture files are in " + pictures_folder$ 721 | --------------------------------------------------------------------------------