ReadWavAndTG

  1. # praat
  2. #
  3. # This is a script that lets you label a bunch of wav files
  4. # in an existing subdir 'wav'.
  5.  
  6. Text writing preferences... UTF-8
  7.  
  8. homePrefix$=""
  9.  
  10. # Create Strings as file list... works relative to where the script is,
  11. # not where the script is run from so we need one copy in each fp's dir.
  12.  
  13. # The script does not create the subdirs 'TextGrid' and 'intervals'
  14. # These must be created first!
  15.  
  16. str1=Create Strings as file list... fileList1 wav/*.wav
  17. Sort
  18.  
  19. nStr=Get number of strings
  20. for i from 1 to nStr
  21.   select 'str1'
  22.  
  23.   wavFileTail$=Get string... i
  24.   tgFileTail$=wavFileTail$-".wav"+".TextGrid"
  25.   ivFileTail$=wavFileTail$-".wav"+".intervals"
  26.  
  27.   wavFile$="wav/"+wavFileTail$
  28.   tgFile$="TextGrid/"+tgFileTail$
  29.   ivFile$="intervals/"+ivFileTail$
  30.  
  31.   # set up for labeling
  32.   # (add a silence/sounding tier as this facilitates keyboard navigation)
  33.   s1=Read from file... 'wavFile$'
  34.   if fileReadable(tgFile$)
  35.     tg1=Read from file... 'tgFile$'
  36.   else
  37.     tg2=To TextGrid (silences)... 100 0 -25 0.2 0.1 silent sounding
  38.     select 's1'
  39.     tg3=To TextGrid... vowels
  40.     plus 'tg2'
  41.     tg1=Merge
  42.     select 'tg2'
  43.     plus 'tg3'
  44.     Remove
  45.     select 'tg1'
  46.   endif
  47.   plus 's1'
  48.   Edit
  49.   if fileReadable("movepause.sh")
  50.     system ./movepause.sh&
  51.   endif
  52.   pause
  53.  
  54.   # write the TextGrid file
  55.   # (extract the second tier as we don't need the silence/sounding tier)
  56.   select 'tg1'
  57.   nt=Get number of tiers
  58.   if nt > 1
  59.     iv1=Extract tier... 2
  60.     tg4=Into TextGrid
  61.   endif
  62.   Write to text file... 'tgFile$'
  63.  
  64.   # also write an interval file with one lab start end per row
  65.   # (might be easier to read for some programs)
  66.   # need to delete it since we append
  67.   filedelete 'ivFile$'
  68.   tierNo=1
  69.   nInt=Get number of intervals... tierNo
  70.  
  71.   for iv from 1 to nInt
  72.     lab$=Get label of interval... tierNo iv
  73.     if lab$ != ""
  74.       stp=Get start point... tierNo iv
  75.       enp=Get end point... tierNo iv
  76.       fileappend "'ivFile$'" 'lab$' 'stp' 'enp''newline$'
  77.     endif
  78.   endfor
  79.  
  80.   plus 's1'
  81.   if nt > 1
  82.     plus 'tg1'
  83.     plus 'iv1'
  84.     plus 'tg4'
  85.   endif
  86.   Remove
  87. endfor