scripting with praat day 4: annotation, labeling, · 2019. 9. 24. · exercise: create a textgrid...

25
Scripting with Praat Day 4: Annotation, labeling, segmenting 1

Upload: others

Post on 19-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

Scripting with Praat Day 4: Annotation, labeling, segmenting 1

Page 2: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

Housekeeping

• Homework 2: • will post later today • will be due by class next Tuesday (not this Friday!)

• Download "day4code" from Canvas for use today

2

Page 3: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

1. Without hard-coding any numbers into your script, use string functions to do the following:

• From input string “Welcome to the linguistics institute”

• Produce the output string “Welcome to the lingstitute”

2. Use numeric and string functions to find for which vowel quality this speaker has maximum and minimum f0 values and the values themselves, given the following inputs:

f0_a = 104 ; f0 for /a/ vowel onset f0_e = 110 ; ... /e/ f0_o = 109 ; ... /o/ f0_i = 117 ; ... /i/ f0_u = 115 ; ... /u/ order$ = “aeoiu”

# Output: The speaker's minimum f0 is ## Hz on vowel /V1/. # The speaker’s maximum f0 is ## Hz on vowel /V2/.

Exercise: behavior of functions

3

Page 4: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

TextGrids and Annotation

4

Page 5: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

Create TextGrid...

• A TextGrid isn't especially useful without a corresponding Sound object,

• but let's create one anyway

• New --> Create TextGrid...

5

Page 6: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

TextGrids Refresher

• A TextGrid is an object type in Praat which behaves kind of like another variable type

• Instead of a simple string or number, though, a TextGrid is essentially a multidimensional array

• It allows us to store and access structured data (usually about an associated sound object)

6

Page 7: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

TextGrids

• Each TextGrid has: • a start time • a stop time and • 1 or more tiers

• Tiers can be:

• IntervalTier: with a series of intervals or

• point tiers: labelled time points (aka TextTier)

7

Page 8: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

TextGrid Examples

8

Page 9: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

Why use TextGrids?

• TextGrids store your segmentation judgments for reference and reproducibility

• They make it easy to visualize transcriptions alongside their sound files

• TextGrids also make it easy to query specific intervals or points in your recordings

• And with scripts you can automate

9

Page 10: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

Exercise: Create a TextGrid

1. Open a new ScriptEditor window and clear your history

2. Record yourself saying the following:• “The question is whether you can make words mean so many different

things.” • Then Save to list and close, and Save .wav file to your computer

3. Create a new TextGrid for this sound object ( Annotate --> To TextGrid... )

4. Name the tiers: words and onsets

5. Create onsets as a point tier and click OK

6. Select both the Sound object and the TextGrid object

7. Paste command history into your ScriptEditor window

10

Page 11: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

Create a TextGrid

selectObject: ”Sound untitled"To TextGrid: "words onsets", "onsets"

# to View and Edit a TextGrid, you select two objects.selectObject: ”Sound untitled"plusObject: ”TextGrid untitled"

# question: what “hidden” action is selectObject performing?

11

Page 12: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

Exercise: Create intervals and points• Add intervals for words: "can", "make", "words", "mean", "different"• Label point onsets for beginning of words: "whether", "mean", "things"

In the TextGridEditor...• Click to insert your cursor at the point in the Sound part of the display where

the interval should start• NOTE: always put boundaries at zero crossings!

• From the Boundary menu, select Add on tier 1• (there are other ways to do this as well: "Enter", or "Command-(F)tierNumber")

• Repeat to add the closing boundary• Click inside the interval on the text tier to select it• Type to add a text label• Save as a text file!

• 2 ways to do this12

Page 13: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

• A TextGrid is just a text file!

• xmin is the start of the time domain and xmax is the end

• size is the number of tiers

• Intervals in an IntervalTier also have xmin, xmax but also text

TextGrid contents (manual)

File type = "ooTextFile"Object class = "TextGrid"

xmin = 0 xmax = 0.4 tiers? <exists> size = 2 item []: item [1]: class = "IntervalTier" name = "words" xmin = 0 xmax = 0.4 intervals: size = 1 intervals [1]: xmin = 0 xmax = 0.4 text = "" item [2]: class = "TextTier" name = "onsets" xmin = 0 xmax = 0.4 points: size = 0

13

Page 14: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

Envisioning TextGrid Structure

item[ ]

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

14

Page 15: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

Envisioning TextGrid Structure

item[ ]

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

15

Page 16: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

xmin xmax

text = ""

Envisioning TextGrid Structure

xmin xmax

1

2

3

1 2 3 4 5 6 7 8 9

1 2 3 4 5 6 7 8 9

1 2 3 4 5 6 7 8 9

4 number mark = ""

number mark = ""

number mark = ""

number mark = ""

number mark = ""

number mark = ""

number mark = ""

number mark = ""

number mark = ""

1 2 3 4 5 6 7 8 9

16

Page 17: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

TextGrid objects

• Let's explore the TextGrid object together

• Can we figure out what all of the dynamic buttons and menus allow us to do?

17

Page 18: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

Exercise: Extracting TextGrid dataUsing the TextGrid object we made earlier, determine whether you placed "phrasal pitch accent" (overall maximum F0) on "can", "make", or "different":

1. Get total # intervals on the interval tier and write to info window2. Look (manually) at your TextGrid to get the number positions of the

relevant intervals3. Use time boundaries retrieved from TextGrid to find local pitch maxima

within those regions (from a Pitch object)4. Find maximum of these local maxima and which word it occurs on5. Append to info: "The maximum pitch of <x> Hz occurs on the word "y"."

Then find the ratio of the time you spent on "whether you can make words" to time spent on "mean so many different".

6. Get # points on the point tier and append to info7. Using times from point tier, calculate ratio of duration of 2nd phrase to 1st

phrase and append to info rounded to 2 decimal places18

Page 19: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

Iteration or "Loops" or…

19

Page 20: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

"When will we be able to have these scripts automatically run on multiple files at once??"

NOW!!

20

Page 21: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

Iteration

• What we need is some way to tell Praat to iterate a specified number of times or until some test condition is satisfied

• Iteration is simply the ability for a programming language to specify that certain blocks of code be executed over and over (from 0 to potential infinity)

• We will see two types of loops:

• list iteration: In Praat, for loops allow us to say "repeat this block for each number from n to k"

• conditional iteration: In Praat, while and until loops allow us to specify a test condition and repeat our block of code either while that test condition is true or until it is true.

21

Page 22: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

List Iteration• e.g. for all gifts from 1 to total_number_of_gifts• pick it up and assess weight

and size,• remove paper,• look excited,• say, "thank you!"

• Notice that there are three parts involved in specifying the repetition of the process:

1. Variable representing the thing you are operating on (here the 'gift'),

2. A starting number, and3. An ending number

22

Page 23: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

List Iteration

• The variable determining number of iterations will be a numeric variable.

• The starting number can be any Praat expression that returns a number (including a hard-coded number)

• The ending number can also be any Praat expression that returns a number

• We will implement this using the reserved words for and endfor surrounding the block of code we want repeated:

for var from <num1> to <num2><do these commands>

endfor

• The variable will increment by 1 on each iteration

23

Page 24: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

1000 coin tosses

# coins.praat

heads = 0tails = 0

for toss from 1 to 1000 if randomInteger(1, 2) = 1 heads = heads + 1 else tails = tails + 1 endifendfor

writeInfoLine: "Praat simulated ", heads, " heads & ",...tails, " tails."

24

Page 25: Scripting with Praat Day 4: Annotation, labeling, · 2019. 9. 24. · Exercise: Create a TextGrid 1. Open a new ScriptEditor window and clear your history 2. Record yourself saying

Loading Files (manual)

# loader.praat - load all of the .wav (lowercase) files# from dir$ into the Objects list

dir$ = "stimuli/"

# Creates object "Strings list" containing only .wav filesstrings = Create Strings as file list: "list", dir$ + "*.wav"

numberOfFiles = Get number of strings

for ifile to numberOfFiles    selectObject: strings    fileName$ = Get string: ifile

    Read from file: dir$ + fileName$endfor

removeObject: strings

25