├── CHANGELOG.txt ├── EXAMPLES.md ├── LICENSE.md ├── README.md ├── TODO.md ├── degg.praat ├── examples ├── dhâlem_iso_1_mis.wav ├── dâlem_iso_1_mis.wav ├── egg_out.txt ├── grids │ ├── dhâlem_iso_1_mis.TextGrid │ ├── dâlem_iso_1_mis.TextGrid │ ├── talam_iso_1_mis.TextGrid │ └── talam_sen_1_mis.TextGrid ├── talam_iso_1_mis.wav └── talam_sen_1_mis.wav ├── exclude.praat ├── getoq.praat ├── howard.praat ├── images ├── dialog1.png ├── eqn1.png ├── eqn2.png ├── pp1.png ├── pp2.png ├── pp3.png ├── pp4.png ├── pp5.png ├── scatter1a.png ├── scatter1b.png ├── scatter2a.png ├── scatter2b.png ├── scatter3a.png ├── scatter3b.png ├── scatter3c.png └── scatter4a.png ├── peakdet.praat ├── plotoq.praat ├── praatdet.praat ├── shelldet.praat ├── smooth.praat ├── splitstring.praat └── writelns.praat /CHANGELOG.txt: -------------------------------------------------------------------------------- 1 | 0.3 (23-08-2020) 2 | 3 | - before manually editing points and periods, pre-process the PointProcess to remove orphan points 4 | - removed pause notification when processing entire files 5 | 6 | 0.2 (16-08-2018) 7 | 8 | - renamed oqmaster.praat to praatdet.praat 9 | - added shelldet.praat for calling from command line 10 | - added code to peakdet.paat to ensure first peak is a closing peak 11 | -------------------------------------------------------------------------------- /EXAMPLES.md: -------------------------------------------------------------------------------- 1 | # Usage examples 2 | 3 | **Update August 2018**: version 0.2 of **praatdet** now always checks to ensure the first peak is a closing peak, which eliminates most of 4 | these errors. Therefore you won't see the behaviour below if you run the new version on the included example files. However, I've left them here as they illustrate the kinds of things that can go wrong. 5 | 6 | 7 | 8 | ## Example 1: processing an interval 9 | 10 | In the first example, we will look just at the intervals on tier 3 labeled ```v``` (demarcating the vowel of interest in each file). In the **Run script: File info** dialog, set the path to the EGG files to be the location of the ```examples``` directory on your local machine. Set *intervalTier* to *3* and *intervalLabel* to *v*. Leave all other parameters in this and the following dialog box at their default values. 11 | 12 | The first file to be processed is ```dhâlem_iso_1_mis.wav```. It is apparent from the Oq scatterplot that something is wrong: 13 | 14 | ![](images/scatter1a.png) 15 | 16 | Inspection of the resulting PointProcess object reveals that this is because the pulse train begins with an opening, rather than a closing peak: 17 | 18 | ![](images/pp1.png) 19 | 20 | Two options are available: (1) remove the offending point or (2) edit the boundary in the TextGrid such that a closing peak is included. Here we will opt for (1), but note that this may [cause problems later](#example2). 21 | 22 | The updated Oq plot looks much more reasonable: 23 | 24 | ![](images/scatter1b.png) 25 | 26 | We can now enter ```0``` in the *Do you want to add/delete any points? (1=yes)* text box and click ```Continue```. Since all these points look reasonable, we can also leave the text box in the following dialog blank and click ```Continue``` again. This will save the modified PointProcess object, write the Oq values to the output text file, and load the next file in the ```examples``` directory. 27 | 28 | Once again we can immediately see that there is a similar problem to the previous file: 29 | 30 | ![](images/scatter2a.png) 31 | 32 | ![](images/pp2.png) 33 | 34 | The Oq plots for the remaining files look OK. Note the (possible) multiple opening peaks in the above example. 35 | 36 | 37 | ## Example 2: processing a file 38 | 39 | Now, perhaps we decide that we are interested in Oq values for other parts of these files, not just those in the ```v``` region. Run ```oqmaster.praat``` again, but this time setting *intervalLabel* to be blank in the initial dialog. This will process the entire file, rather than just a specific region. 40 | 41 | Once again, the first file to be processed is ```dhâlem_iso_1_mis.wav```. The Oq scatterplot once again indicates missing or extraneous periods: 42 | 43 | ![](images/scatter3a.png) 44 | 45 | Didn't we already fix this problem? If we inspect the PointProcess object, we see that the problem is the point we removed in [Example 1](#example1) above: 46 | 47 | ![](images/pp3.png) 48 | 49 | We will need to add this point back in order to correctly calculate Oq for this region. The closer we zoom in, the more accurately we can place our pulsemark: 50 | 51 | ![](images/pp4.png) 52 | 53 | The resulting Oq plot looks much better: 54 | 55 | ![](images/scatter3b.png) 56 | 57 | The first (and possibly last) periods look as though they may be spurious, and looking at the previous PointProcess object gives some indication of why. We could simply remove these two points, or we can remove the entire period in the next step: 58 | 59 | ![](images/dialog1.png) 60 | 61 | This has the advantage of retaining this period in the output, but setting its value to zero, indicating that it was detected, but removed by the user. 62 | 63 | ![](images/scatter3c.png) 64 | 65 | In the next file, we see that Praat has failed to detect an opening peak. 66 | 67 | ![](images/scatter4a.png) 68 | 69 | ![](images/pp5.png) 70 | 71 | However, simply adding this does not fix the issue; the first peak detected in this file "counts" as an opening peak and must therefore be removed. 72 | 73 | If you scroll along you will see a number of examples of multiple opening and closing peaks in this signal. **praatdet** simply selects the most extreme (positive or negative) peak. As discussed extensively elsewhere, this may not be appropriate, and you may wish to remove periods containing such multiple peaks. 74 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # praatdet 2 | 3 | A suite of Praat scripts to determine the open quotient (Oq) and fundamental frequency (f0) based on the EGG waveform. 4 | 5 | 6 | ## Background 7 | 8 | This set of scripts was originally inspired by my attempts to use the [**peakdet**](http://voiceresearch.free.fr/egg/) tools developed by Nathalie Henrich, Cédric Grendrot, and Alexis Michaud. In the course of modifying their code to batch-process large numbers of files, I found myself wishing for a number of other modifications to the general [**peakdet**](http://voiceresearch.free.fr/egg/) workflow. Eventually I decided that the easiest solution would be try and implement something similar myself. I chose to work in Praat primarily because it provides a relatively intuitive and easy-to-use graphical interface for editing pulse trains. Praat comes with its own set of problems and I in no way claim it is superior to Matlab for this purpose; however, I have learned a great deal about working with EGG signals in the process of developing these tools. 9 | 10 | #### Update January 2020: 11 | 12 | As of version 6.1.04, **Praat now includes built-in functionality for working with EGG signals**. I haven't looked carefully at it, but it is no doubt worth exploring if you are interested in EGG. 13 | 14 | ## Warning! 15 | 16 | I make no claims that the implementations here are correct, or that they will give the same results as some other set of EGG tools, etc. I developed them primarily for my own use case, and in order to gain a better appreciation for the issues involved. 17 | 18 | That having been said, the inverse of the ```degg_oq``` measure computed by **praatdet** is usually more or less identical to the ```CQ_PM``` measure output by [**EGGWorks**](https://appsobabble.com/functions/EGGWorks.aspx), while the inverse of the ```howard_oq``` measure is typically comparable to the EGGWorks ```CQ``` measure, depending somewhat on the threshold settings. The measures all appear to be highly correlated, so for *within-language* comparisons, the exact choice is maybe not so critical (as long as it is constant over all items in your analysis). 19 | 20 | ## Comments, suggestions, etc. 21 | 22 | Please use the [issue tracker](https://github.com/kirbyj/praatdet/issues). 23 | 24 | 25 | ## Citing praatdet 26 | 27 | Praatdet can be cited as follows: 28 | 29 | Kirby, James. 2020. Praatdet: Praat-based tools for EGG analysis (v0.3). Retrieved on (date) from [https://github.com/kirbyj/praatdet](https://github.com/kirbyj/praatdet). 30 | 31 | 32 | ## General structure 33 | 34 | **praatdet** assumes that the user has a number of EGG recordings for which s/he would like to obtain Oq estimates. These recordings may either be part of a stereo file (with e.g. a microphone recording on the other channel) or could be mono EGG files. **praatdet** determines opening and closing peaks using the dEGG signal, allows the user to add and delete points, permits the user to disregard particular periods (e.g., due to the presence of multiple opening peaks), and writes the output to a comma-delimited text file. Information about the peaks themselves is also saved in the form of a Praat ```PointProcess``` file. 35 | 36 | Presently, Oq is determined using two methods: 37 | 38 | 1. detection of the opening and closing peaks on the derivative of the EGG signal ("dEGG method"), and 39 | 2. detection of the closing peak using the dEGG signal, and detection of the opening peak using an EGG-based threshold method ("Howard's method"). 40 | 41 | The physiological correlates of peaks in the dEGG signal were studied extensively by Donald Childers and colleagues (e.g. Childers et al. 1986, 1990). Closing peaks are generally easily identified from the dEGG signal, but opening peaks may be indeterminate (Henrich et al. 2004, Michaud 2004). For this reason, while the maximum positive peak in the dEGG is usually used as an indicator the closing instant, an EGG-based threshold method may be used to determine the opening instant. Howard (1995), following Davies et al. (1986) and others, suggest a point where the negative-going Lx cross an amplitude threshold of 3:7 of that cycle's peak-to-peak amplitude. These are the two methods currently implemented in **praatdet**, although the choice of the threshold, which is arbitrary, is controlled by the user. 42 | 43 | The user may or may not have accompying TextGrids where regions of interest have been indicated. In the interest of file management simplicity, **praatdet** keeps just one (potentially user-corrected) PointProcess per file, but permits the user to only annotate/display Oq values for a particular region. For example, you may have a file containing a single word, segmented into onset, nucleus, and coda. In the first instance you may just want to determine Oq for the nucleus, but perhaps later you decide you are interested in the nasal coda as well. Since a single PointProcess object is associated with each EGG file, you can edit the detected peaks for the coda region while retaining your previous edits of the nucleus. For more details, see the [EXAMPLES](EXAMPLES.md) document. 44 | 45 | From the user's perspective, the most important script is ```praatdet.praat```. All other scripts simply encapsulate different aspects of the workflow. 46 | 47 | ### Requirements 48 | - **praatdet** assumes your filenames contain useful metadata about the token (e.g. speaker code, gender, token number, etc.). These will be parsed based on a user-defined delimiter and included in the [output file](#output) as generic columns named *var1, var2...*. 49 | 50 | - It is assumed that tasks such as normalization will happen in a different environment (e.g. R). **praatdet** is narrowly focused on annotating/editing a pulse train object, and extracting Oq values based on it. 51 | 52 | - **praatdet** requires Praat 6 or later. It has been tested with 6.0.24 on both macOS 10.12.3 and Windows 7. Find the latest version at [http://www.praat.org](http://www.praat.org). 53 | 54 | ## Usage 55 | 56 | 1. Run the ```praatdet.praat``` script from within Praat. This will bring up a dialog window prompting you for 57 | 58 | - the location of your EGG files 59 | - the name of your [output file](#output) 60 | - the channel of your audio files containing the EGG signal 61 | - which file in the list you wish to begin processing from 62 | - a delimiter separating meaningful elements of your filenames 63 | 64 | If you are using an existing TextGrid to process just a portion of your files, you can also specify 65 | 66 | - a tier of interest 67 | - a label of interest on this tier 68 | - an interval number of interest 69 | 70 | If you specify both an interval label and an interval number, the number will take precedence, unless it is left as 0 (zero), the default. To process the entire file, set ```intervalLabel``` to be blank and ```intervalNum``` to 0. 71 | 72 | 2. The next options screen prompts you for 73 | 74 | - the minimum and maximum f0 thresholds used by Praat's autocorrelation-based pitch analysis algorithm 75 | - a parameter ```k``` which determines the size of the smoothing window (see [Smoothing](#smoothing) below) 76 | - a threshold for Howard's method (default: 3/7ths) 77 | - the pass frequency for the high-pass filter to remove the Gx signal component (default: 75 Hz) 78 | - the filter cutoff smooth (default: 20 Hz) 79 | - an option to manually edit points and periods 80 | 81 | If ```manualCheck``` is left unchecked, **praatdet** will simply parse all files in the directory, find Oq values, and write them to an [output file](#output). This means that semi-automatic, hand-corrected pitch period detection can be performed, possibly for the entire file, and then Oq values can be extracted for different subsets of each file. 82 | 83 | 3. If manually checking points and periods, **praatdet** will now present the user with a plot of the Oq values for the region of interest, estimated using both the dEGG and Howard methods, and a prompt asking "Do you want to manually add/delete any points?" 84 | 85 | In general, the dEGG and Howard estimates of Oq should be similar. If they are not, or if the values are extremely close to 0 or 1, this usually means that either the first or the last peak detected was not a closing peak. To check this, click ```Continue``` in the **Pause: Manual check options** box. This will bring up an ```Edit``` window showing the dEGG signal and the detected points. **The first and last points should both be positive peaks!** This is because **praatdet** measures periods from closing peak to closing peak. It could have been done the other way, but it wasn't. **UPDATE AUGUST 2020**: some new logic has been added to version 0.3 which should avoid this problem in most cases, and make automated processing safer. 86 | 87 | Note that the ```Edit``` window will automatically zoom in to the region of interest, and that this corresponds to the plot in the ```Picture``` window. 88 | 89 | To add a point, put your cursor where you would like to add a point and select *Add point at cursor* from the **Point** menu (or use the keyboard shortcut). To delete a point or points, select them using the mouse, then choose *Remove point(s)* from the **Point** menu (or use the keyboard shortcut). 90 | 91 | When you are finished, click ```Continue``` in the **Pause: stop or continue** dialog box. 92 | 93 | 4. The Oq estimates will now be re-drawn in the ```Picture``` window, and you will have the option to repeat step 3. If the estimates still look incorrect or differ wildly from one another, you may have missed a point or points; repeat step 3. If the estimates look OK, enter 0 as the value for ```.manualCheck``` and click ```Continue```. 94 | 95 | 5. You will now have the opportunity to remove individual *periods* (not points) from consideration, à la [**peakdet**](http://voiceresearch.free.fr/egg/). You may wish to do this if, for example, you decide that the values at the edges of the utterance are invalid, or if you noticed periods containing double peaks in steps 3-4. I recommend inserting points (or leaving the ones that Praat finds) for double peaks, and then removing the entire period at this step. The advantage of this workflow is that the [output file](#output) will record the time and location of this period, but will not record Oq values for it. This is a simple way of indicating the existence of a double peak. 96 | 97 | To remove periods, enter the period numbers, separated by spaces, in the dialog box. The ```Picture``` display will then update to reflect your changes. Be careful; there is no 'undo' for this procedure, short of processing the file all over again! When you are finished, or if you do not wish to remove any periods, leave the dialog box blank, and click ```Continue```. 98 | 99 | 6. The Oq values as determined by both methods will now be appended to the [output file](#output), and steps 1-6 will be repeated for the next EGG file in the directory. 100 | 101 | For more details and examples of common issues, see the [EXAMPLES](EXAMPLES.md) document. 102 | 103 | 104 | ## Output file format 105 | 106 | The output file (named ```egg_out.txt``` by default) is a comma-delimted text file with a header row plus one row per period per file. Since at present **praatdet** only computes two Oq measures (dEGG and Howard's method), the header looks like 107 | 108 | filename,var1,var2,var3,var4,label,period,start,end,egg_f0,degg_oq,howard_oq 109 | 110 | where the ```var1,var2...``` columns represent variables parsed from your filename. The remaining rows of the output file will look like 111 | 112 | dhâlem_iso_1_mis,dhâlem,iso,1,mis,v,1,0.12421257195168106,0.13106735443332038,145.88354957703206,0.7252252298951782,0.6982139033791485 113 | dhâlem_iso_1_mis,dhâlem,iso,1,mis,v,2,0.13106735443332038,0.13806236081289922,142.959126230305,0.6938484647332952,0.6745684788329395 114 | 115 | Columns 2-5 contain the delimited information contained in the filename. In this example, these columns contain the word token, the context (isolation), the repetition (1), and the speaker code. The next column contains the TextGrid interval label; if the entire file was processed, this will be empty. Following this is the period number (starting at 1, relative to the region specified by the interval label), the start and end times of the period and the f0 (as determined from the location of the dEGG closing peaks), and the Oq measurements. Other measures, such as speed quotient, could be added and appended in a similar fashion. 116 | 117 | ## Behind the scenes 118 | 119 | 120 | ### Peak detection 121 | 122 | Peak detection proceeds in three stages: 123 | 124 | 1. First, take the derivative and use this to find closing peaks: 125 | 126 | Formula... self [col+1] - self [col] 127 | To PointProcess (periodic, peaks)... min max Yes No 128 | 129 | with user-defined min and max. This includes maxima, but not minima, and so finds the closing peaks. These are the most reliable. We could do this on the raw signal or on a smoothed signal; for more on smoothing see [here](#smoothing). 130 | 131 | 2. Next, try to find the opening peaks: 132 | 133 | To PointProcess (periodic, peaks)... min max No Yes 134 | 135 | For more details of Praat's ```To PointProcess (periodic, peaks)....``` algorithm, see [here](http://www.fon.hum.uva.nl/praat/manual/Sound__To_PointProcess__periodic__peaks____.html). 136 | 137 | In order to ensure that the first peak is always a closing peak, the times of the first points in each PointProcess are compared, and the first point of the ```opening``` PointProcess is deleted if it occurs before the first point in the ```closing``` PointProcess. 138 | 139 | 3. These are then combined into a single PointProcess object: 140 | 141 | select PointProcess 'name$'_degg_opening 142 | plus PointProcess 'name$'_degg_closing 143 | Union 144 | 145 | which is then used to subsequent analysis; this is also the object that is ultimately saved. 146 | 147 | One issue with using the Praat ```PointProcess``` is that the time window within which points are searched for is fixed. If this were modified, it could potentially lead to a reduction in errors involving multiple opening peaks. As of version 0.3, **praatdet** attempts to mitigate this by the inclusion of some logic to remove orphan peaks, so that before the user see the PointProcess, it should consist exclusively of positive-negative peak pairs that are not too temporally distant. 148 | 149 | 150 | 151 | ### Smoothing 152 | 153 | Both the Lx and dEGG signals can be smoothed by calculating a *linearly weighted symmetric moving average* 154 | 155 | ![](images/eqn1.png) 156 | 157 | where $t_0$ is the time point to be smoothed, $k$ is the number of points preceding and following $t_0$ to be considered ($\propto$ window size), $x_t$ is the amplitude of the waveform at time $t$, and $\alpha_t$ is the weight at time $t$. 158 | 159 | The smoothed value for a particular time point $t_0$ is found by multiplying each value $x_t$ in the sequence $t-k \ldots t+k$ by a weight $\alpha_t$ corresponding to its position in the series. The sum of the weighted values $\alpha_{t-k} x_{t-k} \ldots \alpha_{t+k} x_{t+k}$ is then divided by the sum of the weights. For example, if $k=3$ and $t_0$ = 16, the smoothed value $\hat{f}(t_0)$ will be 160 | 161 | ![](images/eqn2.png) 162 | 163 | It is possible to efficiently compute these as convolutions but here I just do it the clunky way, constructing an equation like the above based on the user-defined value of $k$. 164 | 165 | Both the Lx and dEGG signals are smoothed using the same function with the same window. 166 | 167 | 168 | ### Howard's method 169 | 170 | Howard's method (encapsulated in the file ```howard.praat```) determines the glottal opening instant by means of a thresholding method. 171 | 172 | 1. First we delimit the period of interest, found using the dEGG closing peaks: 173 | 174 | select PointProcess 'name$'_degg_both 175 | .period_start = Get time from index... .i 176 | .period_end = Get time from index... .i+2 177 | 178 | 2. Then, each period is extracted and normalized: 179 | 180 | Extract part... .period_start .period_end rectangular 1 yes 181 | 182 | # normalize this period 183 | .min = Get minimum... 0 0 Sinc70 184 | .max = Get maximum... 0 0 Sinc70 185 | Formula... (self[col]-.min) / (.max-.min) 186 | 187 | 3. Next, loop through the sample, setting values below the threshold to zero: 188 | 189 | .nsamp = Get number of samples 190 | for .k from 1 to .nsamp 191 | .si = Get value at sample number... eggChan .k 192 | if .si < threshold 193 | ## set all values below threshold to zero 194 | Set value at sample number... 1 .k 0 195 | endif 196 | endfor 197 | 198 | 4. The open period will necessarily start at a point following the peak. We can find this by first determining the peak ```.local_max``` and find the time of the ```.first_zero``` that follows it, determine the sample number ```.zero_samp``` corresponding to the preceding timepoint: 199 | 200 | .local_max = Get time of maximum... 0 0 Sinc70 201 | .first_zero = Get time of minimum... .local_max 0 Sinc70 202 | 203 | # back up one sample for maxmimum explicitness 204 | .zero_samp = Get sample number from time... .first_zero 205 | .open_start = Get time from sample number... .zero_samp-1 206 | 207 | ## Calling from the command line 208 | 209 | If you would like to script **praatdet** from the shell, use ```shelldet.praat```, which collapses both argument windows into a single window. (If all arguments are included in a single form, which is what is needed for Praat to process all command line arguments when called from the shell due to the [single form requirement](http://praat-users.yahoogroups.co.narkive.com/UF4twWwZ/size-of-the-form-windows-in-scipts), the resulting form window will be too big for most screens (since resizing the window is [not possible](http://praat-users.yahoogroups.co.narkive.com/UF4twWwZ/size-of-the-form-windows-in-scipts)). 210 | 211 | 212 | ## Known issues 213 | 214 | - In the Oq plot, the first and last values overlap with the plot border. I'm not sure how to fix this beyond padding the matrices on either end, which means copying the matrices, etc. 215 | 216 | - In the Oq plot, the x axis becomes unreadble for large files, and is uninformative for small files, due to the fixed value for distance of ```Marks bottom every...``` 217 | 218 | - Unlike [peakdet](http://voiceresearch.free.fr/egg/), **praatdet** has nothing intelligent to say about multiple peaks. 219 | 220 | - I have tried to encapsulate different components of the script as functions (procedures). Praat does not have 'real' functions, so be aware that local variables (e.g. ```.formula$```) are globally available. 221 | 222 | ## References 223 | 224 | Childers, D. G., Hicks, D. M., Moore, G. P., and Alsaka, Y. A. (**1986**). “A model for vocal fold vibratory motion, contact area, and the electroglottogram,” J. Acous. Soc. Am. 80, 1309–1320. 225 | 226 | Childers, D. G., Hicks, D. M., Moore, G. P., Eskenazi, L., and Lalwani, A. L. (**1990**). “Electroglottography and vocal fold physiology,” J. Speech Hear. Res. 33, 245–254. 227 | 228 | Henrich N., d'Alessandro C., Castellengo M. and Doval B.. (**2004**). "On the use of the derivative of electroglottographic signals for characterization of nonpathological voice phonation", J. Acous. Soc. Am. 115(3), 1321-1332. 229 | 230 | Michaud, A. (**2004**). “Final consonants and glottalization: new perspectives from Hanoi Vietnamese,” Phonetica 61, 119–146. 231 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | - Currently, the "leave blank for all" design does not work from the shell. Moreover, it's overall a poor design: if you want to look at interval labeled "ons" and interval labeled "nuc" you have to run praatdet twice. 2 | 3 | - Potentially want to allow manual checking even if no periods have been detected in the PointProcess. 4 | 5 | - If "use PP from disk" is checked, Praatdet will fail if there is no PP for some files - maybe have a fallback to create if it doesn't exist? 6 | 7 | - Add functionality to create PointProcess files that indicate the opening instant for threshold measures so that they could be plotted on the first derivative signal (or the filtered EGG signal) in Praat directly 8 | -------------------------------------------------------------------------------- /degg.praat: -------------------------------------------------------------------------------- 1 | ## degg.praat: compute Oq for each period based on dEGG signal (method of Henrich et al., 2004) 2 | 3 | ## James Kirby 4 | ## 4 Jan 2017 5 | 6 | procedure degg 7 | 8 | ## create matrix with five cols: 9 | ## period_num, period_start, period_end, f0, oq 10 | Create simple Matrix... 'name$'_degg nb_periods 5 0 11 | 12 | # .i: points counter 13 | #.i = 1 14 | .i = first_point 15 | 16 | # .j: periods counter 17 | .j = 1 18 | 19 | #while .i < nb_peaks - 2 20 | while .i < last_point - 2 21 | select PointProcess 'name$'_degg_both 22 | .period_start = Get time from index... .i 23 | .period_open = Get time from index... .i+1 24 | .period_end = Get time from index... .i+2 25 | .oq = (.period_end - .period_open) / (.period_end - .period_start) 26 | .f0 = 1 / (.period_end - .period_start) 27 | 28 | # store info for this period 29 | select Matrix 'name$'_degg 30 | Set value... .j 1 .j 31 | Set value... .j 2 .period_start 32 | Set value... .j 3 .period_end 33 | Set value... .j 4 .f0 34 | Set value... .j 5 .oq 35 | 36 | .i = .i + 2 37 | .j = .j + 1 38 | endwhile 39 | endproc 40 | 41 | -------------------------------------------------------------------------------- /examples/dhâlem_iso_1_mis.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/examples/dhâlem_iso_1_mis.wav -------------------------------------------------------------------------------- /examples/dâlem_iso_1_mis.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/examples/dâlem_iso_1_mis.wav -------------------------------------------------------------------------------- /examples/egg_out.txt: -------------------------------------------------------------------------------- 1 | filename,var1,var2,var3,var4,label,method,period,start,end,f0,Oq 2 | -------------------------------------------------------------------------------- /examples/grids/dhâlem_iso_1_mis.TextGrid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/examples/grids/dhâlem_iso_1_mis.TextGrid -------------------------------------------------------------------------------- /examples/grids/dâlem_iso_1_mis.TextGrid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/examples/grids/dâlem_iso_1_mis.TextGrid -------------------------------------------------------------------------------- /examples/grids/talam_iso_1_mis.TextGrid: -------------------------------------------------------------------------------- 1 | File type = "ooTextFile" 2 | Object class = "TextGrid" 3 | 4 | xmin = 0 5 | xmax = 0.5843615006076583 6 | tiers? 7 | size = 3 8 | item []: 9 | item [1]: 10 | class = "IntervalTier" 11 | name = "word" 12 | xmin = 0 13 | xmax = 0.5843615006076583 14 | intervals: size = 1 15 | intervals [1]: 16 | xmin = 0 17 | xmax = 0.5843615006076583 18 | text = "talam" 19 | item [2]: 20 | class = "IntervalTier" 21 | name = "segments" 22 | xmin = 0 23 | xmax = 0.5843615006076583 24 | intervals: size = 7 25 | intervals [1]: 26 | xmin = 0 27 | xmax = 0.04316408930120286 28 | text = "" 29 | intervals [2]: 30 | xmin = 0.04316408930120286 31 | xmax = 0.052718042292655865 32 | text = "t" 33 | intervals [3]: 34 | xmin = 0.052718042292655865 35 | xmax = 0.16385771883635025 36 | text = "a" 37 | intervals [4]: 38 | xmin = 0.16385771883635025 39 | xmax = 0.22235355290068903 40 | text = "l" 41 | intervals [5]: 42 | xmin = 0.22235355290068903 43 | xmax = 0.37305405803062985 44 | text = "a" 45 | intervals [6]: 46 | xmin = 0.37305405803062985 47 | xmax = 0.4961392873514192 48 | text = "m" 49 | intervals [7]: 50 | xmin = 0.4961392873514192 51 | xmax = 0.5843615006076583 52 | text = "" 53 | item [3]: 54 | class = "IntervalTier" 55 | name = "ann" 56 | xmin = 0 57 | xmax = 0.5843615006076583 58 | intervals: size = 5 59 | intervals [1]: 60 | xmin = 0 61 | xmax = 0.04316408930120286 62 | text = "" 63 | intervals [2]: 64 | xmin = 0.04316408930120286 65 | xmax = 0.04698207749956135 66 | text = "b" 67 | intervals [3]: 68 | xmin = 0.04698207749956135 69 | xmax = 0.052718042292655865 70 | text = "p" 71 | intervals [4]: 72 | xmin = 0.052718042292655865 73 | xmax = 0.16385771883635025 74 | text = "v" 75 | intervals [5]: 76 | xmin = 0.16385771883635025 77 | xmax = 0.5843615006076583 78 | text = "" 79 | -------------------------------------------------------------------------------- /examples/grids/talam_sen_1_mis.TextGrid: -------------------------------------------------------------------------------- 1 | File type = "ooTextFile" 2 | Object class = "TextGrid" 3 | 4 | xmin = 0 5 | xmax = 3.6250625 6 | tiers? 7 | size = 3 8 | item []: 9 | item [1]: 10 | class = "IntervalTier" 11 | name = "word" 12 | xmin = 0 13 | xmax = 3.6250625 14 | intervals: size = 6 15 | intervals [1]: 16 | xmin = 0 17 | xmax = 0.8936678321430297 18 | text = "" 19 | intervals [2]: 20 | xmin = 0.8936678321430297 21 | xmax = 1.371586825414392 22 | text = "ngereng" 23 | intervals [3]: 24 | xmin = 1.371586825414392 25 | xmax = 1.5898146762232332 26 | text = "maos" 27 | intervals [4]: 28 | xmin = 1.5898146762232332 29 | xmax = 2.139748860261513 30 | text = "talam" 31 | intervals [5]: 32 | xmin = 2.139748860261513 33 | xmax = 2.685318487283616 34 | text = "sesae" 35 | intervals [6]: 36 | xmin = 2.685318487283616 37 | xmax = 3.6250625 38 | text = "" 39 | item [2]: 40 | class = "IntervalTier" 41 | name = "seg" 42 | xmin = 0 43 | xmax = 3.6250625 44 | intervals: size = 7 45 | intervals [1]: 46 | xmin = 0 47 | xmax = 1.5898146762232332 48 | text = "" 49 | intervals [2]: 50 | xmin = 1.5898146762232332 51 | xmax = 1.7520267429768261 52 | text = "t" 53 | intervals [3]: 54 | xmin = 1.7520267429768261 55 | xmax = 1.8699226008725345 56 | text = "a" 57 | intervals [4]: 58 | xmin = 1.8699226008725345 59 | xmax = 1.9321837960600408 60 | text = "l" 61 | intervals [5]: 62 | xmin = 1.9321837960600408 63 | xmax = 2.0441397066724374 64 | text = "a" 65 | intervals [6]: 66 | xmin = 2.0441397066724374 67 | xmax = 2.139748860261513 68 | text = "m" 69 | intervals [7]: 70 | xmin = 2.139748860261513 71 | xmax = 3.6250625 72 | text = "" 73 | item [3]: 74 | class = "IntervalTier" 75 | name = "ann" 76 | xmin = 0 77 | xmax = 3.6250625 78 | intervals: size = 6 79 | intervals [1]: 80 | xmin = 0 81 | xmax = 1.5898146762232332 82 | text = "" 83 | intervals [2]: 84 | xmin = 1.5898146762232332 85 | xmax = 1.747050602483234 86 | text = "" 87 | intervals [3]: 88 | xmin = 1.747050602483234 89 | xmax = 1.7520267429768261 90 | text = "p" 91 | intervals [4]: 92 | xmin = 1.7520267429768261 93 | xmax = 1.8699226008725345 94 | text = "v" 95 | intervals [5]: 96 | xmin = 1.8699226008725345 97 | xmax = 2.139748860261513 98 | text = "m" 99 | intervals [6]: 100 | xmin = 2.139748860261513 101 | xmax = 3.6250625 102 | text = "" 103 | -------------------------------------------------------------------------------- /examples/talam_iso_1_mis.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/examples/talam_iso_1_mis.wav -------------------------------------------------------------------------------- /examples/talam_sen_1_mis.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/examples/talam_sen_1_mis.wav -------------------------------------------------------------------------------- /exclude.praat: -------------------------------------------------------------------------------- 1 | ## exclude.praat: procedure to safely remove periods from matrices 2 | 3 | ## James Kirby 4 | ## 4 Jan 2017 5 | 6 | procedure exclude 7 | 8 | .excludePeriods = 1 9 | while .excludePeriods == 1 10 | 11 | ## Plot current OQ values 12 | @plotoq: plotName$ 13 | 14 | ## Ask if the user wants to exclude periods 15 | beginPause: "Exclude periods" 16 | comment: "Do you want to manually exclude any periods?" 17 | comment: "WARNING! Cannot be undone!!" 18 | comment: "If yes, enter the period numbers separated by spaces." 19 | comment: "If no, leave blank and click Continue." 20 | text: "to_exclude", "" 21 | endPause: "Continue", 1 22 | 23 | ## Check if there is anything to do 24 | if to_exclude$ != "" 25 | 26 | ## Split out 27 | @splitstring: to_exclude$, " " 28 | 29 | ## First, check that each period is <= the max number of matrix rows 30 | .badPeriod = 0 31 | 32 | ## Both matrices should have the same length, so it 33 | ## shouldn't matter which one we choose 34 | select Matrix 'name$'_degg 35 | .maxRows = Get number of rows 36 | 37 | ## Need to loop through as this isn't a 'real' array... 38 | for i from 1 to splitstring.strLen 39 | .thisPeriod = number(splitstring.array$[i]) 40 | if .thisPeriod > .maxRows 41 | pauseScript: "Period ", .thisPeriod, " does not exist. Please try again." 42 | .badPeriod = 1 43 | endif 44 | endfor 45 | 46 | if .badPeriod != 1 47 | for i from 1 to splitstring.strLen 48 | ## Set everything to 0 for this row of DEGG matrix 49 | select Matrix 'name$'_degg 50 | Set value: number(splitstring.array$[i]), 2, 0 51 | Set value: number(splitstring.array$[i]), 3, 0 52 | Set value: number(splitstring.array$[i]), 4, 0 53 | Set value: number(splitstring.array$[i]), 5, 0 54 | 55 | ## Set everything to 0 for this row of Howard matrix 56 | select Matrix 'name$'_howard 57 | Set value: number(splitstring.array$[i]), 2, 0 58 | Set value: number(splitstring.array$[i]), 3, 0 59 | Set value: number(splitstring.array$[i]), 4, 0 60 | Set value: number(splitstring.array$[i]), 5, 0 61 | endfor 62 | ## else do nothing, go back to top of loop and start again 63 | endif 64 | else 65 | ## Set flag to leave while loop; otherwise plot and ask again 66 | .excludePeriods = 0 67 | endif 68 | endwhile 69 | endproc 70 | -------------------------------------------------------------------------------- /getoq.praat: -------------------------------------------------------------------------------- 1 | ## getoq.praat 2 | 3 | ## James Kirby 4 | ## 23 February 2017 5 | 6 | ## Given an EGG signal (maybe smoothed, maybe not)... compute Oq two ways 7 | 8 | ######################### 9 | ## NOTES AND ISSUES 10 | ######################### 11 | 12 | ## 1. Both the dEGG and Howard methods involve the determination of *periods*, 13 | ## measured from (dEGG) closing peak to closing peak. So the first point in the 14 | ## PointProcess needs to be a closing peak, as does the last. These are computed 15 | ## from the dEGG signal, so the only difference between the methods is in the 16 | ## Oq (not f0) computation;, in particular, with respect to how the start of the 17 | ## opening phase is determined. It is very much up to the USER to insure that 18 | ## the periods have been correctly selected. Both the FIRST and LAST points in 19 | ## the PointProcess should therefore be CLOSING (i.e. positive) peaks. 20 | 21 | ## Note that it is not enough to simply remove the point of uncertain dEGG 22 | ## opening peaks, because the algorithm expects closing-opening peak pairs. 23 | ## Therefore, there is a separate step where whole periods are removed. 24 | 25 | ## 2. At present, nothing intelligent is done about multiple peaks: they 26 | ## are not detected, nor is there an option given to do anything about them. 27 | ## Maxima and minima are currently determined using the built-in Praat function 28 | ## To PointProcess (periodic, peaks)... 29 | 30 | ## 3. It is possible to discard particular periods manually, a la peakdet. 31 | ## This entails keeping track of the periods when adding/deleting points, and 32 | ## then entering these in the next step. If periods are discarded, e.g. due to 33 | ## the presence of multiple opening peaks, they are removed from BOTH methods' 34 | ## matrices (or more precisely, set to 0). 35 | 36 | ## This is likely to be problematic only if the Oq of particular, individual 37 | ## periods is ultimately of interest. In most cases this probably won't 38 | ## matter, because you will interpolate between the missing values at the analysis 39 | ## stage. However, this ultimately depends on your use case. 40 | 41 | ## One advantage of this method - i.e., ensuring that there are points where 42 | ## (you think) there should be pulses, then explicitly removing whole periods 43 | ## at a later stage - is that this preserves information by indicating in the 44 | ## output file that there 'was' a pulse there, but that it was manually removed 45 | ## (i.e., set to 0). 46 | 47 | ## Dependencies 48 | include splitstring.praat 49 | include smooth.praat 50 | include peakdet.praat 51 | include degg.praat 52 | include howard.praat 53 | include writelns.praat 54 | include plotoq.praat 55 | include exclude.praat 56 | 57 | procedure getoq: .manualCheck 58 | 59 | ## Clear Picture window 60 | Erase all 61 | 62 | ## Extract Lx signal 63 | name$ = selected$ ("Sound", 1) 64 | Extract one channel... eggChan 65 | 66 | ## Rename 67 | ch$ = selected$ ("Sound", 1) 68 | select Sound 'name$' 69 | Remove 70 | select Sound 'ch$' 71 | Rename... 'name$' 72 | name$ = selected$ ("Sound", 1) 73 | 74 | ## Create standarized version of file name for plotting purposes 75 | @splitstring: name$, separator$ 76 | plotName$ = "" 77 | for i from 1 to (splitstring.strLen - 1) 78 | plotName$ = plotName$ + splitstring.array$[i] + "-" 79 | endfor 80 | plotName$ = plotName$ + splitstring.array$[splitstring.strLen] 81 | 82 | ## Filter 83 | Copy: "'name$'_filtered" 84 | Filter (pass Hann band)... passFrequency 0 smoothHz 85 | 86 | ## Smooth the filtered signal 87 | Copy: "'name$'_fsmooth" 88 | @smooth: k 89 | Formula... 'smooth.formula$' 90 | 91 | ## Get opening and closing peaks based on dEGG signal 92 | @peakdet 93 | 94 | ############# 95 | ## Main loop 96 | ############# 97 | 98 | ## Set flag 99 | .findOQ = 1 100 | 101 | while .findOQ <> 0 102 | 103 | ############################### 104 | ## Find peaks 105 | ############################### 106 | 107 | ## find total number of opening and closing peaks 108 | select PointProcess 'name$'_degg_both 109 | 110 | ## if we could assume the entire file was relevant than we could just say 111 | # nb_peaks = Get number of points 112 | ## but given we are potentially interested only in a sub-region... 113 | 114 | ## get the first point *following the onset* of the region 115 | first_point = Get high index... start_time 116 | ## get the last point *preceding the offset* of the region 117 | last_point = Get low index... end_time 118 | nb_peaks = (last_point - first_point) + 1 119 | 120 | ## get number of *periods* (close->close) 121 | nb_periods = (nb_peaks / 2) - 1 122 | 123 | #################################### 124 | ## only continue if there is a 125 | ## non-zero number of periods!! 126 | #################################### 127 | 128 | if nb_periods > 0 129 | 130 | #################################### 131 | ## Get Oq using dEGG-only method 132 | #################################### 133 | 134 | @degg 135 | 136 | #################################### 137 | ## Get Oq using Howard's method 138 | #################################### 139 | 140 | @howard 141 | 142 | ##################### 143 | ## Other procedures 144 | ##################### 145 | 146 | #@skewness 147 | 148 | ##################### 149 | ## Plot and check 150 | ##################### 151 | 152 | if .manualCheck <> 0 153 | @plotoq: plotName$ 154 | 155 | beginPause: "Manual check options" 156 | comment: "Do you want to manually add/delete any points? (1=yes)" 157 | integer: ".manualCheck", .manualCheck 158 | endPause: "Continue", 1 159 | 160 | ################################ 161 | ## Add/remove points if desired 162 | ################################ 163 | 164 | if .manualCheck == 1 165 | ## Remove existing Matrix objects since new ones will be created 166 | select Matrix 'name$'_degg 167 | plus Matrix 'name$'_howard 168 | Remove 169 | 170 | ## Now add/remove points 171 | select PointProcess 'name$'_degg_both 172 | plus Sound 'name$'_degg 173 | View & Edit 174 | editor: "PointProcess 'name$'_degg_both" 175 | Zoom: start_time, end_time 176 | endeditor 177 | pause Add missing peaks/delete spurious points 178 | editor: "PointProcess 'name$'_degg_both" 179 | Close 180 | endeditor 181 | endif 182 | 183 | ################################ 184 | ## Exclude periods, if desired 185 | ################################ 186 | 187 | if .manualCheck == 0 188 | ## Call procedure to allow user to exclude periods 189 | @exclude 190 | ## We're done with this file. Set flag and write results to disk 191 | .findOQ = 0 192 | endif 193 | 194 | else 195 | ## Not doing manual check; get me out of this loop! 196 | .findOQ = 0 197 | endif 198 | 199 | endwhile 200 | 201 | ################################## 202 | ## Write to file and save objects 203 | ################################## 204 | @writelns 205 | 206 | ################### 207 | ## Clean up 208 | ################### 209 | select Matrix 'name$'_degg 210 | plus Matrix 'name$'_howard 211 | Remove 212 | 213 | ## otherwise just write the single line 214 | else 215 | @writelns 216 | endif 217 | 218 | endproc 219 | -------------------------------------------------------------------------------- /howard.praat: -------------------------------------------------------------------------------- 1 | ## howard.praat: compute Oq for each period based on Howard's method (Howard, 1995) 2 | 3 | ## James Kirby 4 | ## 4 Jan 2017 5 | 6 | procedure howard 7 | 8 | ## create matrix with five cols: 9 | ## period_num, period_start, period_end, f0, oq 10 | Create simple Matrix... 'name$'_howard nb_periods 5 0 11 | 12 | # .i: points counter 13 | #.i = 1 14 | .i = first_point 15 | 16 | # .j: periods counter 17 | .j = 1 18 | 19 | #for .i from 1 to nb_periods - 1 20 | #while .i < nb_peaks - 2 21 | while .i < last_point - 2 22 | 23 | #select PointProcess 'name$'_degg_closing 24 | select PointProcess 'name$'_degg_both 25 | .period_start = Get time from index... .i 26 | #.period_end = Get time from index... .i+1 27 | .period_end = Get time from index... .i+2 28 | 29 | # select original (filtered, smoothed) signal 30 | select Sound 'name$'_fsmooth 31 | Extract part... .period_start .period_end rectangular 1 yes 32 | 33 | # normalize this period 34 | .min = Get minimum... 0 0 Sinc70 35 | .max = Get maximum... 0 0 Sinc70 36 | Formula... (self[col]-.min) / (.max-.min) 37 | 38 | # open phase begins with the first sample below the threshold 39 | Copy: "'name$'_band_part_zeroed" 40 | .nsamp = Get number of samples 41 | for .k from 1 to .nsamp 42 | .si = Get value at sample number... eggChan .k 43 | if .si < threshold 44 | ## set all values below threshold to zero 45 | Set value at sample number... 1 .k 0 46 | endif 47 | endfor 48 | 49 | # open period starts sometime after the peak 50 | .local_max = Get time of maximum... 0 0 Sinc70 51 | .first_zero = Get time of minimum... .local_max 0 Sinc70 52 | 53 | # back up one sample for maxmimum explicitness 54 | .zero_samp = Get sample number from time... .first_zero 55 | .open_start = Get time from sample number... .zero_samp-1 56 | 57 | ## Optional: draw each period, with a dotted line representing the 58 | ## beginning of the open phase 59 | #Erase all 60 | #Select outer viewport: 0, 6, 0, 4 61 | #select Sound 'name$'_fsmooth_part 62 | #Solid line 63 | #Draw... 0 0 0 0 Yes Curve 64 | #Dotted line 65 | #Draw line... .period_start threshold .period_end threshold 66 | #Draw line... .open_start 0 .open_start 1 67 | #pause 68 | 69 | # compute oq and f0 70 | .oq = (.period_end - .open_start) / (.period_end - .period_start) 71 | .f0 = 1 / (.period_end - .period_start) 72 | 73 | # store info for this period 74 | select Matrix 'name$'_howard 75 | Set value... .j 1 .j 76 | Set value... .j 2 .period_start 77 | Set value... .j 3 .period_end 78 | Set value... .j 4 .f0 79 | Set value... .j 5 .oq 80 | 81 | #appendInfoLine: .period_start, ",", .period_end, ",", .f0, ",", .oq 82 | #appendFileLine: "egg_out.txt", .i, ",", name$, ",howard,", .period_start, ",", .period_end, ",", .f0, ",", .oq 83 | 84 | # clean up 85 | #select Sound 'name$'_band_part 86 | select Sound 'name$'_fsmooth_part 87 | plus Sound 'name$'_band_part_zeroed 88 | Remove 89 | 90 | .i = .i + 2 91 | .j = .j + 1 92 | endwhile 93 | endproc 94 | 95 | -------------------------------------------------------------------------------- /images/dialog1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/images/dialog1.png -------------------------------------------------------------------------------- /images/eqn1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/images/eqn1.png -------------------------------------------------------------------------------- /images/eqn2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/images/eqn2.png -------------------------------------------------------------------------------- /images/pp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/images/pp1.png -------------------------------------------------------------------------------- /images/pp2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/images/pp2.png -------------------------------------------------------------------------------- /images/pp3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/images/pp3.png -------------------------------------------------------------------------------- /images/pp4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/images/pp4.png -------------------------------------------------------------------------------- /images/pp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/images/pp5.png -------------------------------------------------------------------------------- /images/scatter1a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/images/scatter1a.png -------------------------------------------------------------------------------- /images/scatter1b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/images/scatter1b.png -------------------------------------------------------------------------------- /images/scatter2a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/images/scatter2a.png -------------------------------------------------------------------------------- /images/scatter2b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/images/scatter2b.png -------------------------------------------------------------------------------- /images/scatter3a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/images/scatter3a.png -------------------------------------------------------------------------------- /images/scatter3b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/images/scatter3b.png -------------------------------------------------------------------------------- /images/scatter3c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/images/scatter3c.png -------------------------------------------------------------------------------- /images/scatter4a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirbyj/praatdet/989002a4608b996c715e21ec61e67fece350b94e/images/scatter4a.png -------------------------------------------------------------------------------- /peakdet.praat: -------------------------------------------------------------------------------- 1 | ## peakdet.praat: finding opening and closing peaks based on (possibly smoothed) DEGG signal 2 | 3 | ## James Kirby 4 | ## 22 Feb 2017 5 | 6 | ## computes the dEGG signal on the basis of a smoothed, filtered Sp waveform. 7 | ## dEGG signal is then further smoothed using the same window. 8 | 9 | ## there are other smoothing regimes would could entertain/test, but the real 10 | ## problem is with double peaks, which even aggressive smoothing is unlikely to 'solve'. 11 | 12 | procedure peakdet 13 | 14 | # select (filtered, smoothed) Lx signal 15 | select Sound 'name$'_fsmooth 16 | 17 | # take first derivative of waveform 18 | Copy: "'name$'_degg" 19 | Formula... self [col+1] - self [col] 20 | 21 | # smooth this signal (if wS=0, no smoothing) 22 | Formula... 'smooth.formula$' 23 | 24 | ## If there is an existing PointProcess file, use that 25 | if useExistingPP 26 | existing_pprocess$ = "'directory$''name$'_degg_both.PointProcess" 27 | if fileReadable(existing_pprocess$) 28 | Read from file... 'existing_pprocess$' 29 | endif 30 | else 31 | # get closing peaks 32 | To PointProcess (periodic, peaks)... minF0 maxF0 Yes No 33 | Rename... 'name$'_degg_closing 34 | 35 | # what is the time of the first closing point? 36 | closing_point_index = Get high index... start_time 37 | closing_point_time = Get time from index... closing_point_index 38 | 39 | # get opening peaks 40 | select Sound 'name$'_degg 41 | To PointProcess (periodic, peaks)... minF0 maxF0 No Yes 42 | Rename... 'name$'_degg_opening 43 | 44 | # what is the time of the first opening point? 45 | opening_point_index = Get high index... start_time 46 | opening_point_time = Get time from index... opening_point_index 47 | 48 | # before combining, make sure that the first peak is always a closing peak 49 | # this way we always measure closing->closing 50 | if closing_point_time > opening_point_time 51 | Remove point: opening_point_index 52 | endif 53 | 54 | # add them together 55 | select PointProcess 'name$'_degg_opening 56 | plus PointProcess 'name$'_degg_closing 57 | Union 58 | Rename... 'name$'_degg_both 59 | 60 | # now go through remove orphan points 61 | # ensure that all point pairs are positive followed by 62 | # negative and that closing-opening peak pairs occur within 63 | # 1/minF0 sec of one another 64 | num_points = Get number of points 65 | 66 | # initialize counter 67 | p = 1 68 | 69 | while p < (num_points - 1) 70 | select PointProcess 'name$'_degg_both 71 | t_this = Get time from index... p 72 | t_next = Get time from index... p + 1 73 | 74 | select Sound 'name$'_degg 75 | 76 | val_this = Get value at time... 1 't_this' Sinc70 77 | val_next = Get value at time... 1 't_next' Sinc70 78 | 79 | select PointProcess 'name$'_degg_both 80 | 81 | # if next peak is too far away... 82 | if ((t_next - t_this) > 1/minF0) 83 | Remove point... p 84 | num_points = num_points - 1 85 | #pauseScript: "removed point 'p' at time 't_this:3' because next peak too far away" 86 | # if the next peak is close enough... 87 | else 88 | # ...but also positive, treat current peak as orphaned 89 | if (val_next > 0) 90 | Remove point... p 91 | num_points = num_points - 1 92 | #pauseScript: "removed point 'p' at time 't_this:3' because next peak is also positive" 93 | # else move to next closing point 94 | else 95 | p = p + 2 96 | endif 97 | endif 98 | 99 | endwhile 100 | 101 | endif 102 | endproc 103 | -------------------------------------------------------------------------------- /plotoq.praat: -------------------------------------------------------------------------------- 1 | ## plotoq.praat: plot Oq by period for dEGG and Howard methods 2 | 3 | ## James Kirby 4 | ## 4 Jan 2017 5 | 6 | ## Note that if you see periods plotted starting at 0, something is wrong 7 | 8 | procedure plotoq: .plotName$ 9 | 10 | Erase all 11 | 12 | Solid line 13 | 12 14 | 15 | # scatterplots 16 | Select outer viewport: 0, 6, 0, 4 17 | 18 | select Matrix 'name$'_degg 19 | Red 20 | Scatter plot: 1, 5, 0, 0, 0, 1, 2, "+", "no" 21 | 22 | select Matrix 'name$'_howard 23 | Blue 24 | Scatter plot: 1, 5, 0, 0, 0, 1, 2, "+", "no" 25 | 26 | # axes 27 | Marks left: 6, "yes", "yes", "no" 28 | Marks bottom every: 1, 5, "yes", "yes", "no" 29 | Text left: "yes", "OQ" 30 | Text bottom: "yes", "period" 31 | Text top: "no", "'.plotName$'" 32 | 33 | # border 34 | Black 35 | Draw inner box 36 | 37 | # draw grid 38 | Dotted line 39 | i = 5 40 | while i < nb_periods 41 | Draw line... i 0 i 1 42 | i = i + 5 43 | endwhile 44 | 45 | # legend 46 | 10 47 | Red 48 | Text: (nb_periods/10), "Left", 0.125, "Half", "+ dEGG" 49 | 50 | Blue 51 | Text: nb_periods - (nb_periods/10), "Right", 0.125, "Half", "+ Howard" 52 | 53 | endproc 54 | 55 | -------------------------------------------------------------------------------- /praatdet.praat: -------------------------------------------------------------------------------- 1 | ## praatdet.praat: wrapper script to get Oq values for multiple files in a single directory 2 | # 3 | ## James Kirby 4 | ## last update: 17 March 2017 5 | 6 | ## If something goes wrong, you can stop the script and pick up where you 7 | ## left off, by noting the last file in the Strings list that was correctly 8 | ## processed. However be sure to rename your output file, or rename it 9 | ## something new when you restart, or you will overwrite your previous data. 10 | 11 | ######################### 12 | ## USER-DEFINED VARIABLES 13 | ######################### 14 | 15 | ## - directory: path to EGG files 16 | ## - textgrid: path to TextGrids, if applicable (default: same as directory$) 17 | ## - outfile: name of output file (saved in directory$) 18 | ## - extension: file extension for EGG files (.wav, .egg...) 19 | ## - eggChan: channel number of EGG signal 20 | ## - intervalTier, intervalLabel, intervalNum: used to specify a specific 21 | ## portion of the file to edit/extract from. if intervalNum <> 0, this 22 | ## will take precedence over intervalLabel. if intervalLabel == "" and 23 | ## intervalNum == 0, entire file will be processed. 24 | 25 | ## - minF0, maxF0: minimum and maximum pitch values 26 | ## - k: used to calculate window size for smoothing. 27 | ## k = 0 is same as no smoothing. 28 | ## k = 2 > 5-point window; k = 3 > 7-point window; etc. 29 | ## - threshold: Howard's method threshold (default: 3/7) 30 | 31 | form File info 32 | comment Full path to EGG files 33 | text directory /Users/jkirby/Projects/egg/praatdet/examples/ 34 | comment Full path to TextGrids 35 | text textgrids /Users/jkirby/Projects/egg/praatdet/examples/grids/ 36 | comment Name of output file (written to same path as EGG files) 37 | word outfile egg_out.txt 38 | comment Extension for audio file (.wav, .egg, etc.) 39 | word extension .wav 40 | comment Channel of audio file containing EGG signal 41 | integer eggChan 1 42 | comment Start from a particular token? 43 | integer startFile 1 44 | comment Tier of interest (if irrelevant, leave as default) 45 | integer intervalTier 3 46 | comment Label of interval of interest (blank for none/all) 47 | word intervalLabel v 48 | comment Number of interval of interest (0 for none/all) 49 | integer intervalNum 0 50 | comment Separator (-, _ ...) when parsing token names 51 | word separator _ 52 | endform 53 | 54 | beginPause("Parameters") 55 | comment ("Minimum and maximum f0 thresholds") 56 | integer ("minF0", 75) 57 | integer ("maxF0", 600) 58 | comment ("k: Smoothing window size parameter (points on each side)") 59 | integer ("k", 10) 60 | comment ("Threshold for Howard's method") 61 | real ("threshold", 3/7) 62 | comment ("Filter frequency cutoff") 63 | integer ("passFrequency", 40) 64 | comment ("Filter cutoff smoothing") 65 | integer ("smoothHz", 20) 66 | comment ("Manually edit points and periods?") 67 | boolean ("manualCheck", 1) 68 | comment ("Use existing PointProcess files?") 69 | boolean ("useExistingPP", 0) 70 | comment ("Invert signal (if your EGG has closed=down for some reason)") 71 | boolean ("invertSignal", 0) 72 | endPause("Continue", 1) 73 | 74 | ## including getoq.praat includes everything else 75 | include getoq.praat 76 | 77 | clearinfo 78 | 79 | Create Strings as file list... list 'directory$'*'extension$' 80 | 81 | ## parse token filename into var1, var2... 82 | header$ = "filename" 83 | select Strings list 84 | ## NB: assumes all filenames have same structure, so any file will do 85 | sampleFileName$ = Get string... 1 86 | sampleFileName$ = sampleFileName$ - extension$ 87 | @splitstring: sampleFileName$, separator$ 88 | for i from 1 to splitstring.strLen 89 | header$ = "'header$',var'i'" 90 | endfor 91 | 92 | ## Create output file, overwriting if present 93 | writeFileLine: "'directory$''outfile$'", "'header$',label,period,start,end,egg_f0,degg_oq,howard_oq" 94 | ## If we wanted to allow the user to select different/additional measures, would want to modify this 95 | ## so that header was built dynamically 96 | 97 | ## loop through files in directory$ 98 | number_of_files = Get number of strings 99 | for x from startFile to number_of_files 100 | select Strings list 101 | current_file$ = Get string... x 102 | Read from file... 'directory$''current_file$' 103 | filename$ = selected$("Sound") 104 | ## invert signal if necessary 105 | if invertSignal 106 | Formula... -self 107 | endif 108 | 109 | ## default: process entire file if no region of interest is found, 110 | ## or if there is no associated TextGrid 111 | found_region = 0 112 | select Sound 'filename$' 113 | start_time = Get start time 114 | end_time = Get end time 115 | 116 | ## ...but if there is a TextGrid, try to use that instead 117 | gridname$ = current_file$ - extension$ 118 | textgrid$ = "'textgrids$''gridname$'.TextGrid" 119 | if fileReadable (textgrid$) 120 | Read from file... 'textgrid$' 121 | 122 | ## first try to use intervalLabel, if provided 123 | if intervalLabel$ <> "" 124 | ## find start and end of interval of interest 125 | number_of_intervals = Get number of intervals... intervalTier 126 | for y from 1 to number_of_intervals 127 | select TextGrid 'gridname$' 128 | tmp$ = Get label of interval... intervalTier y 129 | if tmp$ == intervalLabel$ 130 | found_region = 1 131 | start_time = Get start time of interval... intervalTier y 132 | end_time = Get end time of interval... intervalTier y 133 | endif 134 | endfor 135 | 136 | ## if intervalNum is given, use that instead 137 | elsif intervalNum <> 0 138 | start_time = Get start time of interval... intervalTier intervalNum 139 | end_time = Get end time of interval... intervalTier intervalNum 140 | found_region = 1 141 | ## overwrite intervalLabel$ with something more useful 142 | ## problem: doing this means that we will not enter this condition next time 143 | #intervalLabel$ = Get label of interval... intervalTier intervalNum 144 | endif 145 | 146 | else 147 | ## if there is no TextGrid, process the whole file 148 | beginPause: "No such file" 149 | comment: "File <'gridname$'.TextGrid> does not exist in directory" 150 | comment: "'textgrid$'" 151 | comment: "Using whole file as region of interest." 152 | endPause: "Continue", 1 153 | found_region = 1 154 | endif 155 | 156 | ## if a region of interest has been identified, call main getoq function 157 | if found_region == 1 158 | select Sound 'filename$' 159 | @getoq: manualCheck 160 | endif 161 | 162 | select all 163 | minus Strings list 164 | 165 | Remove 166 | 167 | clearinfo 168 | endfor 169 | 170 | ## clean up 171 | select Strings list 172 | Remove 173 | 174 | printline All done. 175 | -------------------------------------------------------------------------------- /shelldet.praat: -------------------------------------------------------------------------------- 1 | ## shelldet.praat: wrapper script to get Oq values for multiple files in a single directory from command line 2 | # 3 | ## James Kirby 4 | ## last update: 17 August 2018 5 | 6 | ## If something goes wrong, you can stop the script and pick up where you 7 | ## left off, by noting the last file in the Strings list that was correctly 8 | ## processed. However be sure to rename your output file, or rename it 9 | ## something new when you restart, or you will overwrite your previous data. 10 | 11 | ######################### 12 | ## USER-DEFINED VARIABLES 13 | ######################### 14 | 15 | ## - directory: path to EGG files 16 | ## - textgrid: path to TextGrids, if applicable (default: same as directory$) 17 | ## - outfile: name of output file (saved in directory$) 18 | ## - extension: file extension for EGG files (.wav, .egg...) 19 | ## - eggChan: channel number of EGG signal 20 | ## - intervalTier, intervalLabel, intervalNum: used to specify a specific 21 | ## portion of the file to edit/extract from. if intervalNum <> 0, this 22 | ## will take precedence over intervalLabel. if intervalLabel == "" and 23 | ## intervalNum == 0, entire file will be processed. 24 | 25 | ## - minF0, maxF0: minimum and maximum pitch values 26 | ## - k: used to calculate window size for smoothing. 27 | ## k = 0 is same as no smoothing. 28 | ## k = 2 > 5-point window; k = 3 > 7-point window; etc. 29 | ## - threshold: Howard's method threshold (default: 3/7) 30 | form File info 31 | comment Full path to EGG files 32 | text directory /Users/jkirby/Projects/egg/praatdet/examples/ 33 | comment Full path to TextGrids 34 | text textgrids /Users/jkirby/Projects/egg/praatdet/examples/grids/ 35 | comment Name of output file (written to same path as EGG files) 36 | word outfile egg_out.txt 37 | comment Extension for audio file (.wav, .egg, etc.) 38 | word extension .wav 39 | comment Channel of audio file containing EGG signal 40 | integer eggChan 1 41 | comment Start from a particular token? 42 | integer startFile 1 43 | comment Tier of interest (if irrelevant, leave as default) 44 | integer intervalTier 3 45 | comment Label of interval of interest (blank for none/all) 46 | word intervalLabel v 47 | comment Number of interval of interest (0 for none/all) 48 | integer intervalNum 0 49 | comment Separator (-, _ ...) when parsing token names 50 | word separator _ 51 | comment Minimum and maximum f0 thresholds 52 | integer minF0 75 53 | integer maxF0 600 54 | comment k: Smoothing window size parameter (points on each side) 55 | integer k 10 56 | comment Threshold for Howard's method 57 | real threshold 3/7 58 | comment Filter frequency cutoff 59 | integer passFrequency 40 60 | comment Filter cutoff smoothing 61 | integer smoothHz 20 62 | comment Manually edit points and periods? 63 | boolean manualCheck 0 64 | comment Use existing PointProcess files, if available? 65 | boolean useExistingPP 0 66 | comment Invert signal (if your EGG has closed=down for some reason) 67 | boolean invertSignal 0 68 | endform 69 | 70 | ## including getoq.praat includes everything else 71 | include getoq.praat 72 | 73 | clearinfo 74 | 75 | Create Strings as file list... list 'directory$'*'extension$' 76 | 77 | ## parse token filename into var1, var2... 78 | header$ = "filename" 79 | select Strings list 80 | ## NB: assumes all filenames have same structure, so any file will do 81 | sampleFileName$ = Get string... 1 82 | sampleFileName$ = sampleFileName$ - extension$ 83 | @splitstring: sampleFileName$, separator$ 84 | for i from 1 to splitstring.strLen 85 | header$ = "'header$',var'i'" 86 | endfor 87 | 88 | ## Create output file, overwriting if present 89 | writeFileLine: "'directory$''outfile$'", "'header$',label,period,start,end,egg_f0,degg_oq,howard_oq" 90 | ## If we wanted to allow the user to select different/additional measures, would want to modify this 91 | ## so that header was built dynamically 92 | 93 | ## loop through files in directory$ 94 | number_of_files = Get number of strings 95 | for x from startFile to number_of_files 96 | select Strings list 97 | current_file$ = Get string... x 98 | Read from file... 'directory$''current_file$' 99 | filename$ = selected$("Sound") 100 | ## invert signal if necessary 101 | if invertSignal 102 | Formula... -self 103 | endif 104 | 105 | ## default: process entire file if a region of interest is found, 106 | ## or if there is no associated TextGrid 107 | found_region = 0 108 | select Sound 'filename$' 109 | start_time = Get start time 110 | end_time = Get end time 111 | 112 | ## ...but if there is a TextGrid, try to use that instead 113 | gridname$ = current_file$ - extension$ 114 | textgrid$ = "'textgrids$''gridname$'.TextGrid" 115 | if fileReadable (textgrid$) 116 | Read from file... 'textgrid$' 117 | 118 | ## first try to use intervalLabel, if provided 119 | if intervalLabel$ <> "" 120 | ## find start and end of interval of interest 121 | number_of_intervals = Get number of intervals... intervalTier 122 | for y from 1 to number_of_intervals 123 | select TextGrid 'gridname$' 124 | tmp$ = Get label of interval... intervalTier y 125 | if tmp$ == intervalLabel$ 126 | found_region = 1 127 | start_time = Get start time of interval... intervalTier y 128 | end_time = Get end time of interval... intervalTier y 129 | endif 130 | endfor 131 | 132 | ## if intervalNum is given, use that instead 133 | elsif intervalNum <> 0 134 | start_time = Get start time of interval... intervalTier intervalNum 135 | end_time = Get end time of interval... intervalTier intervalNum 136 | found_region = 1 137 | ## overwrite intervalLabel$ with something more useful 138 | ## problem: doing this means that we will not enter this condition next time 139 | #intervalLabel$ = Get label of interval... intervalTier intervalNum 140 | endif 141 | 142 | else 143 | ## if there is no TextGrid, process the whole file 144 | # beginPause: "No such file" 145 | # comment: "File <'gridname$'.TextGrid> does not exist in directory" 146 | # comment: "'textgrid$'" 147 | # comment: "Using whole file as region of interest." 148 | # endPause: "Continue", 1 149 | found_region = 1 150 | endif 151 | 152 | ## if a region of interest has been identified, call main getoq function 153 | if found_region == 1 154 | select Sound 'filename$' 155 | @getoq: manualCheck 156 | endif 157 | 158 | select all 159 | minus Strings list 160 | 161 | Remove 162 | 163 | clearinfo 164 | endfor 165 | 166 | ## clean up 167 | select Strings list 168 | Remove 169 | 170 | printline All done. 171 | -------------------------------------------------------------------------------- /smooth.praat: -------------------------------------------------------------------------------- 1 | ## smooth.praat: computes weighted symmetrical moving average 2 | 3 | ## James Kirby 4 | ## 4 Jan 2017 5 | 6 | ## This basically constructs a Praat Formula... that works for moving window 7 | ## averages of arbitrary length, to avoid having to manually average and 8 | ## weight e.g. 1*( (i-10)+(i+10) ) + 2*( (i-9) + (i+9) ) + ... etc. 9 | 10 | procedure smooth: .wS 11 | 12 | ## wS = window size = number of points on either side of point of interest to be taken into account 13 | ## slightly confusing but so too is allowing the user to specify the size of the window itself; 14 | ## what does an even (=asymmetric) window size mean? 15 | 16 | # multipler of current value: wS+1 17 | .nMult = .wS+1 18 | 19 | # denominator: sum of weights 20 | .denom = .wS+1 21 | for i from 1 to .wS 22 | .denom = .denom + 2*i 23 | endfor 24 | 25 | # construct formula 26 | .formula$ = "(" + string$(.nMult) + " * self [col]" 27 | j = .wS 28 | while j > 0 29 | .formula$ = .formula$ + " + " + string$(j) + " * (self [col - " + string$(.nMult-j) + "] + self [col + " + string$(.nMult-j) + "])" 30 | j = j - 1 31 | endwhile 32 | .formula$ = .formula$ + " ) / " + string$(.denom) 33 | 34 | # to access in main script body: use smooth.formula$ 35 | endproc 36 | 37 | -------------------------------------------------------------------------------- /splitstring.praat: -------------------------------------------------------------------------------- 1 | ## splitstring.praat: parse a string into an "array" 2 | 3 | ## James Kirby 4 | ## 23 February 2017 5 | ## (adapted from a procedure by Paul Boersma) 6 | 7 | procedure splitstring: .string$, .sep$ 8 | .strLen = 0 9 | repeat 10 | .sepIndex = index (.string$, .sep$) 11 | if .sepIndex <> 0 12 | .value$ = left$ (.string$, .sepIndex - 1) 13 | .string$ = mid$ (.string$, .sepIndex + 1, 10000) 14 | else 15 | .value$ = .string$ 16 | endif 17 | .strLen = .strLen + 1 18 | .array$[.strLen] = .value$ 19 | until .sepIndex = 0 20 | endproc 21 | 22 | ## Call with e.g. 23 | ## 24 | ## @splitstring: name$, separator$ 25 | ## 26 | ## then access with 27 | ## 28 | ## splitstring.strLen 29 | ## splitstring.array$[i] 30 | ## 31 | ## etc. 32 | -------------------------------------------------------------------------------- /writelns.praat: -------------------------------------------------------------------------------- 1 | ## writeln.praat: parse filename, write output file and PointProcess object 2 | 3 | ## James Kirby 4 | ## 23 February 2017 5 | 6 | 7 | procedure writelns 8 | 9 | ## Parse filename into array 10 | @splitstring: gridname$, separator$ 11 | 12 | ## Turn this into a comma-separated list 13 | lingVars$ = "" 14 | for i from 1 to splitstring.strLen 15 | lingVars$ = lingVars$ + splitstring.array$[i] + "," 16 | endfor 17 | 18 | ## Note that because Praat Matrix objects can't contain characters, 19 | ## cols 2-5 of rows that have been 'discarded' are set to 0. 20 | ## This could potentially be handled more gracefully here, or can 21 | ## be dealt with at the analysis stage (e.g., by replacing 0s with 22 | ## NAs in your statistical analysis software). 23 | 24 | ## get interval label if we don't have it 25 | if intervalNum <> 0 26 | select TextGrid 'gridname$' 27 | printIntervalLabel$ = Get label of interval... intervalTier intervalNum 28 | else 29 | printIntervalLabel$ = intervalLabel$ 30 | endif 31 | 32 | ## if you have at least one period: 33 | if nb_periods > 0 34 | for i from 1 to nb_periods-1 35 | myFileLine$ = "" 36 | 37 | ## DEGG 38 | select Matrix 'name$'_degg 39 | currPeriod = Get value in cell... i 1 40 | pstart = Get value in cell... i 2 41 | pend = Get value in cell... i 3 42 | f0 = Get value in cell... i 4 43 | degg_oq = Get value in cell... i 5 44 | myFileLine$ = myFileLine$ + name$ + "," + lingVars$ + printIntervalLabel$ + ",'currPeriod','pstart','pend','f0','degg_oq'" 45 | 46 | ## Howard 47 | select Matrix 'name$'_howard 48 | howard_oq = Get value in cell... i 5 49 | myFileLine$ = myFileLine$ + ",'howard_oq'" 50 | 51 | ## If you want to add other measures, just continue to append them here 52 | 53 | ## Now, write to file 54 | appendFileLine: "'directory$''outfile$'", "'myFileLine$'" 55 | endfor 56 | 57 | ## if not: 58 | else 59 | myFileLine$ = name$ + "," + lingVars$ + printIntervalLabel$ + ",NA,NA,NA,NA,NA,NA" 60 | appendFileLine: "'directory$''outfile$'", "'myFileLine$'" 61 | endif 62 | 63 | ## Save PointProcess object 64 | select PointProcess 'name$'_degg_both 65 | Save as text file... 'directory$''name$'_degg_both.PointProcess 66 | 67 | endproc 68 | --------------------------------------------------------------------------------