######################################################################
#### Robert Felty <robfelty - indiana.edu>
#### 2008
#### This script comes with no warranty. Use at your own risk

## Mark segment boundaries for CVCs
## This script loops over a directory, opening each .wav file one at a time,
## and creates a textgrid, then opens the textgrid and sound together. At this
## point, the user can add 2 points to the textgrid marking the boundaries
## between phonemes. A pause dialog box is opened (it may be hidden behind the
## textgrid window)). Clicking on continue will write the measurements to the
## specified file. The current sound object will be deleted, and the next file
## will be opened.
## 

######################################################################
endeditor
clearinfo

# nextFileNum allows you to start where you left off
nextFileNum=136

basedir$="/home/robfelty/Desktop/DansCVCs/"


edited$= "edited"
indir$ = "'basedir$'H_norm/"
outfile$ = "rob.txt"
echo fnum'tab$'fname'tab$'boundary1'tab$'boundary2'tab$'
fileappend "'basedir$''outfile$'" fnum'tab$'fname'tab$'boundary1'tab$'boundary2'newline$'

Create Strings as file list... list 'indir$'*.wav
Sort
numFiles = Get number of strings
for i from nextFileNum to numFiles

  #get name of selected sound
  select Strings list
  currentFile$ = Get string... 'i'
  Read from file... 'indir$''currentFile$'

  word$ = selected$ ("Sound")


  To TextGrid... "boundaries" boundaries
  plus Sound 'word$'
  Edit
  pause add boundaries, then next stimulus will appear
  editor TextGrid 'word$'
    vowelbegin = Get start of selection
    vowelend = Get end of selection
    midpoint = vowelbegin + ((vowelend-vowelbegin)/2)
  endeditor



  select TextGrid 'word$'

  boundary1 = Get time of point... 1 1
  boundary2 = Get time of point... 1 2

  plus Sound 'word$'
  Remove
  #print to info window
  print 'i''tab$''word$''tab$''boundary1:4''tab$''boundary2:4''newline$'
  fileappend "'basedir$''outfile$'" 'i''tab$''word$''tab$''boundary1:4''tab$''boundary2:4''newline$'
endfor
pause all done with this dir
