Difference between revisions of "Get dur"

From Phonlab
Jump to navigationJump to search
(Created page with "<code>get_dur</code> script =================== This script illustrates basic usage of the [https://github.com/rsprouse/audiolabel <code>audiolabel</code> library]. It reads a P…")
 
m
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
The <code>get_dur</code> script illustrates basic usage of the [https://github.com/rsprouse/audiolabel <code>audiolabel</code> library]. It reads a Praat textgrid and reports time values for labels that match a set of target labels.
<code>get_dur</code> script
 
===================
 
   
  +
<nowiki>
This script illustrates basic usage of the [https://github.com/rsprouse/audiolabel <code>audiolabel</code> library]. It reads a Praat textgrid and reports time values for labels that match a set of target labels.
 
 
<code>
 
 
#!/usr/bin/env python
 
#!/usr/bin/env python
   
 
# Simple script to measure phone durations.
 
# Simple script to measure phone durations.
   
Usage = "meas_dur file1.TextGrid"
+
Usage = "meas_dur file.TextGrid"
   
 
import sys
 
import sys
 
import audiolabel
 
import audiolabel
   
  +
# Get the textgrid name from the input arguments and create a LabelManager object.
 
try:
 
try:
sys.argv[1] != None
 
 
tg = sys.argv[1]
 
tg = sys.argv[1]
 
lm = audiolabel.LabelManager(from_file=tg, from_type="praat")
 
except IndexError:
 
except IndexError:
raise Exception("\nUsage: " + Usage)
+
print "Usage: " + Usage
  +
sys.exit(1)
   
 
# List of labels for which we want duration measurements.
 
# List of labels for which we want duration measurements.
 
phones = ["P", "T", "K", "B", "D", "G"]
 
phones = ["P", "T", "K", "B", "D", "G"]
   
  +
# Print the header line.
print "phone\tt1\tt2\tduration"
+
print "phone\tword\tt1\tt2\tduration"
lm = audiolabel.LabelManager(from_file=tg, from_type="praat")
 
  +
for label in lm.tier('phone'):
 
  +
# Loop over all the labels in the 'phone' tier.
if label.text in phones:
 
 
for plab in lm.tier('phone'):
print "{:s}\t{:1.4f}\t{:1.4f}\t{:1.4f}".format(
 
  +
# Check to see if the current label text is one of our target phones.
label.text, label.t1, label.t2, label.duration
 
 
if plab.text in phones:
  +
# Grab the corresponding label from the 'word' tier.
  +
wlab = lm.tier('word').label_at(plab.center)
  +
# Print values from the phone label and corresponding word label.
 
print "{:s}\t{:s}\t{:1.4f}\t{:1.4f}\t{:1.4f}".format(
 
plab.text, wlab.text, plab.t1, plab.t2, plab.duration
 
)
 
)
</code>
+
</nowiki>

Latest revision as of 12:02, 19 October 2015

The get_dur script illustrates basic usage of the audiolabel library. It reads a Praat textgrid and reports time values for labels that match a set of target labels.

#!/usr/bin/env python

# Simple script to measure phone durations.

Usage = "meas_dur file.TextGrid"

import sys
import audiolabel

# Get the textgrid name from the input arguments and create a LabelManager object.
try:
    tg = sys.argv[1]
    lm = audiolabel.LabelManager(from_file=tg, from_type="praat")
except IndexError:
    print "Usage: " + Usage
    sys.exit(1)

# List of labels for which we want duration measurements.
phones = ["P", "T", "K", "B", "D", "G"]

# Print the header line.
print "phone\tword\tt1\tt2\tduration"

# Loop over all the labels in the 'phone' tier.
for plab in lm.tier('phone'):
    # Check to see if the current label text is one of our target phones.
    if plab.text in phones:
        # Grab the corresponding label from the 'word' tier.
        wlab = lm.tier('word').label_at(plab.center)
        # Print values from the phone label and corresponding word label.
        print "{:s}\t{:s}\t{:1.4f}\t{:1.4f}\t{:1.4f}".format(
            plab.text, wlab.text, plab.t1, plab.t2, plab.duration
        )