# duration.praat # -------------- # A script for duration extraction # # Author: Pablo Arantes # Created: 2008-05-05 # Modified: 2012-06-14 # # Purpose: # Takes one or multiple segmented TextGrid files and extracts duration values # in milliseconds for non-empty intervals in a user-specified interval tier. # # Input: # Previously segmented TextGrid files # # Output: # Duration in milliseconds for segmented TextGrid are written to a tab-separated report file. # # Comments: # Script file and user files don't need to be in the same file directory. # # Copyright (C) 2008-2012 Pablo Arantes # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . form duration.praat comment If "Single file" is selected you will be prompted to select a TextGrid file. comment If "Multiple files" is selected you have to provide the path to a folder containing TextGrid files. choice Mode: 1 button Single file button Multiple files comment Directory where the TextGrid files are (only if "Multiple files" mode is selected): sentence Folder c:\someDir\ comment Tier from which duration should be extracted: integer Tier 1 comment Report folder and name: sentence Report c:\someDir\someName.txt endform ### TO DO LIST: ### - rewrite documentation ### - Give the user the option to choose between different column separators ### (tab, comma, space) filedelete 'report$' if mode = 1 fileappend 'report$' label'tab$'position'tab$'dur'newline$' else fileappend 'report$' file'tab$'label'tab$'position'tab$'dur'newline$' endif if mode = 1 files = 1 file$ = chooseReadFile$ ("Choose a TextGrid file") if file$ <> "" grid = Read from file... 'file$' endif else list = Create Strings as file list... fileList 'folder$'*.TextGrid files = Get number of strings if files < 1 exit There are no TextGrid files on 'folder$'. endif endif for file to files if mode = 2 select list file$ = Get string... 'file' grid = Read from file... 'folder$''file$' file$ = selected$("TextGrid") endif test = Is interval tier... tier if test = 0 exit Tier 'tier' in TextGrid 'file$' is not an interval tier. endif sel = Extract one tier... tier tab = Down to Table... no 6 no no n = Get number of rows for i to n label$ = object$[tab, i, 2] start = object[tab, i, 1] end = object[tab, i, 3] dur = round((end - start) * 1000) if mode = 1 fileappend 'report$' 'label$''tab$''i''tab$''dur''newline$' else fileappend 'report$' 'file$''tab$''label$''tab$''i''tab$''dur''newline$' endif endfor select grid plus sel plus tab Remove endfor if mode = 2 select list Remove endif