![]() ![]() We also have to understand the selection behavior when we open a file or create a new object. Open a new scripting window and try these commands out yourself. We can also select multiple items, using "plusObject", and we can deselect an item with "minusObject". Selecting and deselecting multiple objects, understanding Praat's selection behavior This means that a well-written script will work on any folder full of similar files, on anyone's machine, even if the files have different names. Every time I open a file, I save it's object number to a variable, and then I can refer to it throughout the script. Let's say I want to open all of the sound and TextGrid files in some folder, but all of the files obviously have different names. Whenever we open a file or create a new object programmatically we can save its number as a variable like this, and we don't need to know its name beforehand. ![]() Just as a reminder, when we created the new sound object with "Extract part", Praat returned its number so that we can easily select it later. StartTime = Get starting point: tierNum, intNum Make sure to include code to select the TextGrid object, and print out the value of 'part' at the end of the script. We can use "Get starting point" and "Get end point". We want to get the start and end time for Tier 2 Interval 2 from the TextGrid, so select it and find an appropriate command. Part = Extract part: startTime, endTime, windowShape, relWidth, preserveTimes We still don't know the start and stop time, but we'll make some blank variables that we'll fill in in a second: Let's convert this command to code, and save the result to a variable called "part". Open it and see its arguments, and we see that the important thing we need to know is the time range (in seconds) of the section we want to extract. I strongly encourage you to try to write this yourself before continuing, you'll get a lot more out of it.īut now here's my version: We want to extract from the sound object, so select it and find a command in the right that will extract part of the sound. Let's extract the sound in the second interval from this tier (the vowel "e"), and make it its own sound object. Select "Sound be" and "TextGrid be" and click View & Edit, and note that the second tier has split this syllable into segments. An example using object selection: Extracting part of a sound I'll explain why I think so after we do this next example. For one, those numbers are going to be different every time you use Praat, so we absolutely cannot hard-code them (object 7 will most likely be different the next time you run the script), but in truth there are some great advantages to using the numbers, and I generally prefer them. At first glance, the numbers version may seem to be the lamer option. Which version you should use depends on your situation. Change which version of the command is commented and uncommented, and run it again. Now to make sure both commands work, click on a different object like "Sound ba", comment out the command you don't want to test (put a hashtag in front of one of the selectObject commands), and run the code. In a blank scripting window, type in the two following ways we can select the object "Sound a", adjusting the numbers to work with what you currently have open. The numbering starts at 1 when you open Praat, and will keep going up as you create more objects or open more files. Look to the left of each object, and note that they have been assigned a unique number. ![]() There are basically two ways we can select files in Praat: by using the object's name or by using its number in the object window. Hopefully you now see plainly why we need to learn how to select objects in Praat via script: we won't get very far without it. This should generate an error saying that the given command is not available, which is true, because that command is only available when a text grid is selected, and right now a sound is selected (other times this error simply means you've spelled the command wrong). Open a Praat scripting window, type this in, and run it: What we want to note here is that we have different commands available to us when different object types are selected. Now select a sound and its corresponding TextGrid together (ctrl), and look at the available commands. Now click on a text grid and look at the commands. Though we already went through this, click on a sound file and look at the available commands on the right. TextGrid files in sampleData/ (if you haven't downloaded the accompanying files, go to the Downloads page from the top right menu). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |