Praat


About


Praat is a program for "doing phonetics by computer" created by Paul Boersma. Find out more about it on it's home page.

On this page


Various tips, tricks, scripts and thoughts on Praat. Hide contents

ArtSynth1

nocheck select all
nocheck Remove

length = 2
half = length/2

Articulatory synthesis tutorial
Create Speaker... speaker Male 2
Create Artword... hallo length
Set target... 0 0.5 Interarytenoid
Set target... length 0.5 Interarytenoid
Set target... 0 1 LevatorPalatini
Set target... length 1 LevatorPalatini
Set target... 0 0.1 Lungs
Set target... 0.03 0 Lungs

#Set target... half 0.7 Masseter
#Set target... half 0.2 OrbicularisOris

Set target... 0.0 -1 Hyoglossus
Set target... length 1 Hyoglossus
Set target... 0.0 -0.4 Masseter
Set target... length -0.4 Masseter

#Set target... 0.0 0.4 Hyoglossus
#Set target... length 0.4 Hyoglossus
#Set target... 0.0 -0.4 Masseter
#Set target... length -0.4 Masseter

select Speaker speaker
plus Artword hallo
To Sound... 22050 25 0 0 0 0 0 0 0 0 0
Play

BeatrootAnalysis

Beatroot analysis


Beatroot by Simon Dixon is a system for beat tracking. Here's a small script for integrating this analysis with Praat.

  1. s1=selected("Sound")
  2. Write to WAV file... /tmp/forbeatroot.wav
  3. system java -jar /home/johanf/dev/beatroot/beatroot-0.5.3.jar /tmp/forbeatroot.wav -o /tmp/forbeatroot.txt
  4. tg1=To TextGrid... beats
  5. m1=Read Matrix from raw text file... /tmp/forbeatroot.txt
  6.  
  7. nr = Get number of rows
  8. for i to nr
  9.   b'i' = Get value in cell... i 1
  10. endfor
  11.  
  12. select 'tg1'
  13. for i to nr
  14.   Insert boundary... 1 b'i'
  15. endfor
  16.  
  17. select 'm1'
  18. Remove
  19.  
  20. select 's1'
  21. plus 'tg1'
  22. Edit

Concatenate all wavs

Load all wav files in a dir and concatenate recoverably. Save Sound and TextGrid to collection.

  1. form Concatenate all wavs
  2.     word dir /home/johanf/
  3. endform
  4. wavPattern$ = dir$+"*.wav"
  5. Create Strings as file list... fileList 'wavPattern$'
  6. ns = Get number of strings
  7. for i to ns
  8.     dum$ = Get string... i
  9.     str'i'$ = dum$
  10. endfor
  11. for i to ns
  12.    wavFileName$ = dir$+str'i'$
  13.    s'i' = Read from file... 'wavFileName$'
  14.    #name$ = selected$("Sound")
  15.    #name2$ = replace$(name$,"_"," ",5)
  16. endfor
  17.  
  18. select s1
  19. for i from 2 to ns
  20.     plus s'i'
  21. endfor
  22. Concatenate recoverably
  23. outFileName$ = dir$+"all.Collection"
  24. Write to binary file... 'outFileName$'

DLHFloorCeiling

s1=selected("Sound")
s1$=selected$("Sound")
p1=noprogress To Pitch... 0.01 60 750
q75=Get quantile... 0 0 0.75 Hertz
q25=Get quantile... 0 0 0.25 Hertz
ceiling=1.5*q75
floor=0.75*q25
select 's1'
Edit
editor Sound 's1$'
Pitch settings... floor ceiling Hertz autocorrelation automatic
vfloor=(floor div 50)*50
vceiling=((ceiling div 50)+1)*50
Advanced pitch settings... vfloor vceiling no 15 0.03 0.45 0.01 0.35 0.14
printline floor: 'floor:0' ceiling: 'ceiling:0'
printline vfloor: 'vfloor:0' vceiling: 'vceiling:0'

Draw spectrum and formants

This draws a spectrum with LPC smoothing and formants based on the selection in a TextGridEditor.

  1. form Draw spectrum and formants
  2.   positive Number_of_formants: 4
  3.   choice Maximum_formant_(Hz): 1
  4.     button Custom
  5.     button 5000
  6.     button 5500
  7.   positive Custom_value_(Hz) 5000
  8. endform
  9. if maximum_formant = 1
  10.   maxf = custom_value
  11. endif
  12. if maximum_formant = 2
  13.   maxf = 5000
  14. endif
  15. if maximum_formant = 3
  16.   maxf = 5500
  17. endif
  18. printline 'maxf'
  19. resf=maxf*2
  20.  
  21. cur = Get cursor
  22. endeditor
  23. s1=selected("Sound")
  24. tg1=selected("TextGrid")
  25. select 's1'
  26. Extract part... cur-0.0125 cur+0.0125 Gaussian1 1 no
  27. s2=selected("Sound")
  28. Resample... 'resf' 50
  29. s3=selected("Sound")
  30. To Formant (burg)... 0 'number_of_formants' 'maxf' 0.025 50
  31. f1=selected("Formant")
  32. Down to FormantTier
  33. ft1=selected("FormantTier")
  34. Down to TableOfReal... yes no
  35. tor1=selected("TableOfReal")
  36. nc = Get number of columns
  37. for i from 2 to nc
  38.   fn=i-1
  39.   fv'fn' = Get value... 1 i
  40.   dum = fv'fn'
  41.   printline F'fn': 'dum:0'
  42. endfor
  43. select 's3'
  44. #Pre-emphasize (in-line)... 50
  45. To Spectrum... yes
  46. spec1=selected("Spectrum")
  47. To Ltas (1-to-1)
  48. ltas1=selected("Ltas")
  49. max = Get maximum... 0 0 None
  50. min = Get minimum... 0 0 None
  51. ce=ceiling(max/20)*20
  52. fl=floor(min/20)*20
  53. select 'spec1'
  54. #Erase all
  55. Plain line
  56. Line width... 1
  57. Draw... 0 'maxf' 'fl' 'ce' yes
  58. Marks bottom every... 1 1000 yes yes no
  59. pause
  60. LPC smoothing... 'number_of_formants' 50
  61. spec2=selected("Spectrum")
  62. Line width... 2
  63. fl=fl+20
  64. ce=ce+20
  65. Draw... 0 'maxf' 'fl' 'ce' no
  66. Axes... 0 'maxf' 0 1
  67. Line width... 1
  68. Dotted line
  69. for i from 2 to nc
  70.   fn=i-1
  71.   dum = fv'fn'
  72.   tdum=dum+150
  73.   tt$ = "F"+"'fn'"
  74.   Draw line... 'dum' 0 'dum' 1
  75.   Text... 'tdum' Centre 0.96 Half 'tt$'
  76. endfor
  77.  
  78. plus 'spec1'
  79. plus 'ltas1'
  80. plus 'tor1'
  81. plus 'ft1'
  82. plus 'f1'
  83. plus 's3'
  84. plus 's2'
  85. Remove
  86. select 's1'
  87. plus 'tg1'

<screenshot ?>


Drawing an F1-F2 plot (to appear...)

/* Not finished */

Some code here.


F1F2-plot from TextGridEditor

This draws a Bark scaled F1/F2-plot based on an annotated waveform. Other scales are possible as well.

  1. # Draw f1f2-plots of vowels current editor
  2. #clearinfo
  3.  
  4. # 1: Bark
  5. # 2: Mel
  6. # 3: Semitones
  7. # 4: Erb
  8. procedure WarpHz type inHz
  9. warp=inHz
  10. if type = 1
  11.   warp=hertzToBark(inHz)
  12. elsif type = 2
  13.   warp=hertzToMel(inHz)
  14. elsif type = 3
  15.   warp=hertzToSemitones(inHz)
  16. elsif type = 4
  17.   warp=hertzToErb(inHz)
  18. endif
  19. endproc
  20.  
  21. Move cursor to... 0
  22. first_interval = 0
  23. highest_end = 0
  24. vow=0
  25.  
  26. warpType=1
  27. intoVowel=0.5
  28.  
  29. repeat
  30.   lab$=Get label of interval
  31.   st=Get starting point of interval
  32.   en=Get end point of interval
  33.   if en > highest_end
  34.     highest_end = en
  35.   endif
  36.   if st = 0
  37.     first_interval=first_interval+1
  38.   endif
  39.   Select next interval
  40.   if first_interval < 2 && lab$ != ""
  41.     #printline 'st' 'en' 'lab$' 'first_interval'
  42.     vow=vow+1
  43.     time'vow'=st+((en-st)*intoVowel)
  44.     lab'vow'$=lab$
  45.   endif
  46. until first_interval > 1
  47.  
  48. #clearinfo
  49. Time step settings... fixed   0.01   100
  50. Show analyses... yes no no yes no highest_end
  51. for i from 1 to vow
  52.   dumtime = time'i'
  53.   dumlab$ = lab'i'$
  54.   #printline 'dumtime' 'dumlab$'
  55.   Move cursor to... dumtime
  56.   f1'i' = Get first formant
  57.   f2'i' = Get second formant
  58.   #f3'i' = Get third formant
  59.   #printline 'dumtime' 'dumlab$' 'f1' 'f2'
  60.   #fm1 = hertzToBark(f1'i')
  61.   #fm2 = hertzToBark(f2'i')
  62.   #fm3 = hertzToBark(f3'i')
  63.   #printline fm1_'i' = 'fm1'
  64.   #printline fm2_'i' = 'fm2'
  65.   #printline fm3_'i' = 'fm3'
  66. endfor
  67. endeditor
  68.  
  69. #fappendinfo /home/johanf/formant_values.psc
  70. #Erase all
  71.  
  72. #clearinfo
  73. from_x=3000
  74. to_x=500
  75. step_x=-500
  76. from_y=1000
  77. to_y=200
  78. step_y=-200
  79.  
  80. call WarpHz warpType from_x
  81. from_x_Warp=warp
  82. call WarpHz warpType to_x
  83. to_x_Warp=warp
  84. call WarpHz warpType from_y
  85. from_y_Warp=warp
  86. call WarpHz warpType to_y
  87. to_y_Warp=warp
  88.  
  89. Axes... from_x_Warp to_x_Warp from_y_Warp to_y_Warp
  90. Draw inner box
  91. One mark left... to_y_Warp no yes no 'to_y'
  92. One mark left... from_y_Warp no yes no 'from_y'
  93. One mark top... to_x_Warp no yes no 'to_x'
  94. One mark top... from_x_Warp no yes no 'from_x'
  95.  
  96. x=from_x+step_x
  97. while x > to_x
  98.   call WarpHz warpType x
  99.   x_Warp=warp
  100.   One mark top... x_Warp no no yes
  101.   x=x+step_x
  102. endwhile
  103.  
  104. y=from_y+step_y
  105. while y > to_y
  106.   call WarpHz warpType y
  107.   y_Warp=warp
  108.   One mark left... y_Warp no no yes
  109.   y=y+step_y
  110. endwhile
  111.  
  112. clearinfo
  113. #t1=Create TableOfReal... name vow 2
  114. for i from 1 to vow
  115.   dumlab$ = lab'i'$
  116.   dumf1=f1'i'
  117.   dumf2=f2'i'
  118.  
  119.   #Set value... i 1 dumf1
  120.   #Set value... i 2 dumf2
  121.  
  122.   printline 'dumlab$' 'dumf1:0', 'dumf2:0'
  123.   #printline ipasign'i'$="'dumlab$'"
  124.    
  125.   call WarpHz warpType dumf1
  126.   f1=warp
  127.   call WarpHz warpType dumf2
  128.   f2=warp
  129.  
  130.   Text... 'f2' Centre 'f1' Half 'dumlab$'
  131. endfor
  132.  
  133. #fappendinfo /home/johanf/ipasigns.psc

Generating cropped PNG files from Praat EPS

When converting a praat eps file to png (e.g. for web publishing) with gs, the whole Picture window display is included in the png file, rendering lots of extra white space. One solution is to crop the image using the Netpbm package.

Example:

  1. gs -sDEVICE=ppmraw -dTextAlphaBits=4 -r120 -sOutputFile=- -sNOPAUSE -q praat.eps -c showpage -c quit | pnmcrop | pnmmargin -white 10 | pnmtopng > praat.png

Or just use the EPSCrop option:

  1. gs -sDEVICE=png16m -dTextAlphaBits=4 -dEPSCrop -r120 -dSAFER -dBATCH -dNOPAUSE -sOutputFile=$soundDir/$pngFile2 -q $soundDir/$epsFile

See a demo here: mbrola.php


Harmonicity

(just a sketch)

  1. clearinfo
  2. s1 = selected("Sound")
  3.  
  4. for i from 1 to 21
  5.         lb = barkToHertz(i-1)
  6.         hb = barkToHertz(i+1)
  7.         cf'i' = (lb+hb)/2
  8.         bw'i' = hb - lb
  9. endfor
  10.  
  11. gender$ = "m"
  12. #maxform = 5500
  13. minpitch = 125
  14. if gender$ == "m"
  15.   #maxform = 5000
  16.   minpitch = 60
  17. endif
  18.  
  19. for j from 1 to 21
  20.   select 's1'
  21.   ccf = cf'j'
  22.   cbw = bw'j'
  23.   Filter (gammatone)... 'ccf' 'cbw'
  24.   s2 = selected("Sound")
  25.   noprogress To Harmonicity (cc)... 0.01 'minpitch' 0.1 1
  26.   h1 = selected("Harmonicity")
  27.   meanh = Get mean... 0 0
  28.   if meanh != undefined
  29.     hm'j'=meanh
  30.   else
  31.     hm'j'=0
  32.   endif
  33.   plus 's2'
  34.   Remove
  35. endfor
  36.  
  37. for j from 1 to 21
  38.   ccf = cf'j'
  39.   chm = hm'j'
  40.   printline -- 'ccf:0' 'chm'
  41. endfor

Intensity of fundamental component

This analyses a Sound and gives a Pitch object with the curve of the intensity (instead of the frequency) of the fundamental component, which is obtained from a Spectrogram of the Sound.

  1. form Intensity of fundamental component
  2.   real Time_step_(s): 0.0 (= auto)
  3.   positive Pitch_floor_(Hz): 75.0
  4.   positive Pitch_ceiling_(Hz): 600.0
  5.   boolean Info_window 0
  6. endform
  7. ns=numberOfSelected("Sound")
  8. if ns != 1
  9.   exit Please select exactly one Sound object!
  10. endif
  11. s1=selected("Sound")
  12. select 's1'
  13.  
  14. if time_step = 0
  15.   tstep=0.75/pitch_floor
  16. else
  17.   tstep=time_step
  18. endif
  19. winsize=3/pitch_floor
  20. hw=winsize/2
  21. ct=tstep/2
  22.  
  23. dur = Get total duration
  24. noprogress To Pitch... 'time_step' 'pitch_floor' 'pitch_ceiling'
  25. p1=selected("Pitch")
  26. nfr=Get number of frames
  27. for i from 1 to nfr
  28.   fct'i' = Get time from frame number... 'i'
  29.   pi'i'= Get value in frame... 'i' Hertz
  30. endfor
  31.  
  32. select 's1'
  33. noprogress To Spectrogram... 'winsize' 5000 'tstep' 20 Gaussian
  34. spec1=selected("Spectrogram")
  35.  
  36. for i from 1 to nfr
  37.   cct=fct'i'
  38.   cp=pi'i'
  39.   pint'i' = 0
  40.   if cp != undefined
  41.     pow=Get power at... 'cct' 'cp'
  42.     pint'i' = 10 * log10(pow*20000)
  43.   endif
  44.   cpint=pint'i'
  45.   #printline 'cct' 'cp' 'pow' 'cpint'
  46. endfor
  47.  
  48. select 'p1'
  49. To Matrix
  50. m1=selected("Matrix")
  51. for i from 1 to nfr
  52.   val=pint'i'
  53.   Set value... 1 'i' val
  54. endfor
  55. To Pitch
  56. p2=selected("Pitch")
  57. mean=Get mean... 0 0 Hertz
  58. max=Get maximum... 0 0 Hertz Parabolic
  59. stdev=Get standard deviation... 0 0 Hertz
  60. if info_window
  61.   clearinfo
  62.   printline Time_step Window_size Mean Stdev Max
  63.   printline 'tstep' 'winsize' 'mean' 'stdev' 'max'
  64. endif
  65. select 'm1'
  66. Remove
  67. select 'p2'

Test of websvn display:



IPA label based on shortest formant distance

This labels a selection in a TextGridEditor with an IPA vowel character. The label is based on comparing the sound in the selection by shortest formant distance to a number of example vowels. The vowels are taken from the wikipedia entries on vowels.

  1. include formant_values.psc
  2. include ipasigns.psc
  3.  
  4. dir$="/media/polo/JohanFrid/wp_vokaler/"
  5. wavPattern$ = dir$+"*.wav"
  6.  
  7. ssel=selected("Sound")
  8. stg=selected("TextGrid")
  9.  
  10. s1s=Extract sound selection (preserve times)
  11. endeditor
  12.  
  13. s1=Resample... 16000 50
  14. st = Get starting time
  15. en = Get finishing time
  16. testdur = Get total duration
  17.  
  18.  
  19. # male voice
  20. noprogress To Formant (burg)... 0 5 5000 0.025 50
  21. for1=selected("Formant")
  22. fm1=Get mean... 1 0 0 Bark
  23. fm2=Get mean... 2 0 0 Bark
  24. fm3=Get mean... 3 0 0 Bark
  25.  
  26. if 0
  27. # female voice
  28. noprogress To Formant (burg)... 0 5 5500 0.025 50
  29. for1=selected("Formant")
  30. fm1=Get mean... 1 0 0 Bark
  31. fm2=Get mean... 2 0 0 Bark
  32. fm3=Get mean... 3 0 0 Bark
  33.  
  34. fm1=fm1-1
  35. fm2=fm2-1
  36. fm3=fm3-1
  37. endif
  38.  
  39. bestdist=1000000000
  40. clearinfo
  41. for i from 1 to 28
  42.   #a$="0"+"'i'"
  43.   #a$=right$(a$,2)
  44.  
  45.   dist = abs(fm1-fm1_'i')+abs(fm2-fm2_'i')+abs(fm3-fm3_'i')
  46.   #dist = abs(fm1-fm1_'i')+abs(fm2-fm2_'i')
  47.  
  48.   ipa$=ipasign'i'$
  49.   dum1=fm1_'i'
  50.   dum2=fm2_'i'
  51.   dum3=fm3_'i'
  52.  
  53.   printline 'ipa$' 'fm1:1'-'dum1:1' 'fm2:1'-'dum2:1' 'fm3:1'-'dum3:1'
  54.  
  55.  
  56.   if dist < bestdist
  57.     bestdist = dist
  58.     bestsound = i
  59.   endif
  60. endfor
  61.  
  62. str1=Create Strings as file list... fileList 'wavPattern$'
  63.  
  64. printline --------
  65.  
  66. ipa$=ipasign'bestsound'$
  67. printline 'bestsound' 'ipa$' 'bestdist'
  68.  
  69. s2=Create Sound... sineWithNoise 0 0.2 16000 0
  70. select 'str1'
  71. dum$ = Get string... bestsound
  72. thesound$=dir$+dum$
  73. s3s=Read from file... 'thesound$'
  74. s3=Resample... 16000 50
  75.  
  76. select 's1'
  77. plus 's2'
  78. plus 's3'
  79. s4=Concatenate
  80. Play
  81.  
  82. select 's1s'
  83. plus 's1'
  84. plus 'for1'
  85. plus 's2'
  86. plus 's3s'
  87. plus 's3'
  88. plus 's4'
  89. plus 'str1'
  90. Remove
  91.  
  92. select stg
  93. ipatier=0
  94. nt = Get number of tiers
  95. for i from 1 to nt
  96.   tn$ = Get tier name... 'i'
  97.   if tn$ = "IPAlabel"
  98.     ipatier=i
  99.   endif 
  100. endfor
  101. if ipatier=0
  102.   Insert interval tier... 1 IPAlabel
  103.   ipatier=1
  104. endif
  105. nocheck Insert boundary... 1 st
  106. nocheck Insert boundary... 1 en
  107. mid = (en+st)/2
  108. cin=Get interval at time... 1 mid
  109. ipa$=ipasign'bestsound'$
  110. Set interval text... 1 cin 'ipa$'
  111. plus ssel

PosDataAnalyzer

PosDataAnalyzer


Quite lengthy script for analysing pos data from the ag500. Lets you focus in on a part of the waveform and then plot a trace of the sensord in the picture window. Extensive use of demo window for interactivity. Lots of undo associated with drawing in the picture window.

  1. form Pos data analyzer
  2.   sentence majorPath X:\Lingvistik\FONM23\articulatory_data
  3.   word minorPath SPTE_xxxx
  4.   natural currentSweep 10
  5.   comment Plot boundaries (please set sensible values here)
  6.   integer left_X_boundaries -80
  7.   integer right_X_boundaries 80
  8.   integer left_Y_boundaries -80
  9.   integer right_Y_boundaries 80
  10.   comment Channel options
  11.   word TT_Channel Ch1
  12.   word TD_Channel Ch2
  13.   word UL_Channel Ch3
  14.   word LL_Channel Ch4
  15.   #sentence Categories HAT/HET/HIT/HUT/HUT/HYT/HÅT/HÄT/HÖT
  16. endform
  17. nocheck select all
  18. nocheck Remove
  19. Erase all
  20.  
  21. #currentSweep=10
  22. #majorPath$="C:\Users\ling-jfr\Downloads\artuculatory_data"
  23. #minorPath$="SPTE_sara"
  24. artX1=left_X_boundaries
  25. artX2=right_X_boundaries
  26. artY1=left_Y_boundaries
  27. artY2=right_Y_boundaries
  28. ttChX$=tT_Channel$+"_X"
  29. tdChX$=tD_Channel$+"_X"
  30. ulChX$=uL_Channel$+"_X"
  31. llChX$=lL_Channel$+"_X"
  32. ttChZ$=tT_Channel$+"_Z"
  33. tdChZ$=tD_Channel$+"_Z"
  34. ulChZ$=uL_Channel$+"_Z"
  35. llChZ$=lL_Channel$+"_Z"
  36. wavTop=100
  37. wavBottom=80
  38. specTop=80
  39. specBottom=40
  40. garnish$="yes"
  41. analyzed=0
  42.  
  43. # uncommented to get sane syntax highlighting
  44. #if windows
  45. #  separator$ = "\"
  46. #else
  47. #  separator$ = "/"
  48. #endif
  49.  
  50. timeRange1=0
  51. timeRange2=0
  52. logName$=majorPath$+separator$+minorPath$+separator$+"pda_"+replace_regex$(date$ (),"[ :]", "_",0)+".log"
  53. #call split "'categories$'" /
  54. #printline 'split.arr$[1]'
  55. goto GETDATA
  56.  
  57. label CLEANDATA
  58. select 's1'
  59. plus 'spec1'
  60. plus 't1'
  61. plus 'tor2'
  62. Remove
  63. goto GETDATA
  64.  
  65. label GETDATA
  66. sweepAsString$=right$("000"+"'currentSweep'",4)
  67. wavName$=majorPath$+separator$+minorPath$+separator$+"wav"+separator$+sweepAsString$+".wav"
  68. posName$=majorPath$+separator$+minorPath$+separator$+"pos"+separator$+sweepAsString$+".txt"
  69. #s1=Read from file... C:\Users\ling-jfr\Downloads\artuculatory_data\SPTE_sara\wav\0011.wav
  70. s1=Read from file... 'wavName$'
  71. soundDur=Get total duration
  72. timeRange1=0
  73. timeRange2=soundDur
  74. spec1=noprogress To Spectrogram... 0.005 5000 0.002 20 Gaussian
  75. # articulatory data
  76. #t1=Read Table from tab-separated file... C:\Users\ling-jfr\Downloads\artuculatory_data\SPTE_sara\pos\0011.txt
  77. t1=Read Table from tab-separated file... 'posName$'
  78. tor1=Down to TableOfReal... 0
  79. #tor2=tor1
  80.  
  81. # low pass filter
  82. nCol=Get number of columns
  83. for i from 1 to nCol
  84.   colLab'i'$=Get column label... i
  85. endfor
  86.  
  87. m1=To Matrix
  88. m2=Transpose
  89. s2=To Sound
  90. Scale times to... 0 1
  91. Override sampling frequency... 200
  92. s3=Filter (pass Hann band)... 0 10 1
  93. m3=Down to Matrix
  94. m4=Transpose
  95. tor2=To TableOfReal
  96. for i from 1 to nCol
  97.   current$=colLab'i'$
  98.   Set column label (index)... i 'current$'
  99. endfor
  100.  
  101. select 'tor1'
  102. plus 'm1'
  103. plus 'm2'
  104. plus 's2'
  105. plus 's3'
  106. plus 'm3'
  107. plus 'm4'
  108. Remove
  109.  
  110. goto REDRAW
  111.  
  112. label REDRAW
  113. demo Erase all
  114. demo Select outer viewport... 0 100 0 100
  115. demo Axes... 0 100 0 100
  116. demo Black
  117. demo Line width... 1
  118. demo Solid line
  119.  
  120. # Title
  121. demo Text... 50 centre 100 top 'sweepAsString$'
  122.  
  123. # buttons
  124. call DrawButton 0 20 12 18 Play
  125. call DrawButton 25 45 12 18 Analyze
  126. call DrawButton 50 70 12 18 Undo
  127. call DrawButton 75 95 12 18 Next
  128.  
  129. call DrawButton 12 32 24 30 Left
  130. call DrawButton 37 58 28 34 Zoom in
  131. call DrawButton 37 58 20 26 Zoom out
  132. call DrawButton 63 83 24 30 Right
  133.  
  134. procedure DrawButton .leftX .rightX .topY .bottomY .buttonText$
  135.   demo Paint rectangle... pink .leftX .rightX .topY .bottomY
  136.   demo Draw rectangle... .leftX .rightX .topY .bottomY
  137.   .textX = (.rightX + .leftX) / 2
  138.   .textY = (.topY + .bottomY) / 2
  139.   demo Text... .textX centre .textY half '.buttonText$'
  140. endproc
  141.  
  142. # waveform
  143. demo Select outer viewport... 0 100 'wavBottom' 'wavTop'
  144. select 's1'
  145. demo Draw... timeRange1 timeRange2 0 0 yes Curve
  146.  
  147. # spectrogram
  148. demo Select outer viewport... 0 100 'specBottom' 'specTop'
  149. select 'spec1'
  150. demo Paint... timeRange1 timeRange2 0 0 100 yes 50 6 0 yes
  151.  
  152. myDemoX1=timeRange1
  153. myDemoX2=timeRange1
  154. currentMark=1
  155. goto MARK
  156.  
  157. label WAIT
  158. while demoWaitForInput ( )
  159.   if demoClicked ( )
  160.     demo Select outer viewport... 0 100 0 100
  161.     demo Axes... 0 100 0 100
  162.     goto PLAY demoClickedIn (0, 20, 12, 18)
  163.     goto ANALYZE demoClickedIn (25, 45, 12, 18)
  164.     goto UNDO demoClickedIn (50, 70, 12, 18)
  165.     goto NEXT demoClickedIn (75, 95, 12, 18)
  166.  
  167.     goto VIEWLEFT demoClickedIn (12, 32, 24, 30)
  168.     goto ZOOMIN demoClickedIn (37, 58, 28, 34)
  169.     goto ZOOMOUT demoClickedIn (37, 58, 20, 26)
  170.     goto VIEWRIGHT demoClickedIn (63, 83, 24, 30)
  171.  
  172.     demo Undo
  173.  
  174.     demo Select outer viewport... 0 100 'specBottom' 'specTop'
  175.     demo Axes... 0 'soundDur' 0 5000
  176.     goto GETMOUSEX demoClickedIn (0, soundDur, 0, 5000)
  177.     demo Undo
  178.   endif
  179.   #goto GETMOUSEX demoClickedIn (0, soundDur, 0, 5000)
  180.   #goto PLAY demoClickedIn
  181.   #goto MARKLEFT demoInput ("1")
  182.   #goto MARKRIGHT demoInput ("2")
  183.   goto EXIT demoInput ("x")
  184. endwhile
  185.  
  186. label ZOOMIN
  187. demo Undo
  188. viewDur=timeRange2-timeRange1
  189. viewCenter=(timeRange2+timeRange1)/2
  190. viewDur=viewDur*0.5
  191. timeRange1=viewCenter-(viewDur/2)
  192. timeRange2=viewCenter+(viewDur/2)
  193. goto REDRAW
  194.  
  195. label ZOOMOUT
  196. demo Undo
  197. viewDur=timeRange2-timeRange1
  198. viewCenter=(timeRange2+timeRange1)/2
  199. viewDur=viewDur*2
  200. timeRange1=viewCenter-(viewDur/2)
  201. timeRange2=viewCenter+(viewDur/2)
  202. if timeRange1<0.001
  203.   timeRange1=0
  204. endif
  205. if timeRange2>soundDur
  206.   timeRange2=soundDur
  207. endif
  208. goto REDRAW
  209.  
  210. label VIEWLEFT
  211. demo Undo
  212. moveDelta=1
  213. if timeRange1<moveDelta
  214.   moveDelta=timeRange1
  215. endif
  216. timeRange1=timeRange1-moveDelta
  217. timeRange2=timeRange2-moveDelta
  218. goto REDRAW
  219.  
  220. label VIEWRIGHT
  221. demo Undo
  222. moveDelta=1
  223. if timeRange2>soundDur-moveDelta
  224.   moveDelta=soundDur-timeRange2
  225. endif
  226. timeRange1=timeRange1+moveDelta
  227. timeRange2=timeRange2+moveDelta
  228. goto REDRAW
  229.  
  230. label NEXT
  231. demo Undo
  232. currentSweep=currentSweep+1
  233. goto CLEANDATA
  234.  
  235. label PLAY
  236. demo Undo
  237. #printline play 'myDemoX1' 'myDemoX2'
  238. # check
  239. if myDemoX1 == 0 && myDemoX2 == 0
  240.   goto WAIT
  241. endif
  242. if (myDemoX1 < myDemoX2)
  243.   mySoundSamp1 = myDemoX1
  244.   mySoundSamp2 = myDemoX2
  245. else
  246.   mySoundSamp1 = myDemoX2
  247.   mySoundSamp2 = myDemoX1
  248. endif
  249. select 's1'
  250. s2=Extract part... mySoundSamp1 mySoundSamp2 rectangular 1 no
  251. Play
  252. Remove
  253. goto WAIT
  254.  
  255. label UNDO
  256. demo Undo
  257. Undo
  258. Undo
  259. Undo
  260. Undo
  261. Undo
  262. Undo
  263. Undo
  264. Undo
  265. #printline undo
  266. analyzed=analyzed-1
  267. if analyzed<0
  268.   analyzed=0
  269. endif
  270. if analyzed=0
  271.   garnish$="yes"
  272. endif
  273. goto WAIT
  274.  
  275. label EXIT
  276. demo Select outer viewport... 0 100 0 100
  277. demo Axes... 0 100 0 100
  278. demo Text... 50 centre 0 bottom Script has finished. Please close this window manually...
  279. #printline out of while
  280. exit
  281.  
  282. label GETMOUSEX
  283. demo Undo
  284.  
  285. demo Undo
  286. demo Undo
  287. demo Undo
  288. demo Undo
  289. demo Undo
  290. if currentMark==1
  291.   myDemoX1=demoX ( )
  292.   currentMark=2
  293. else
  294.   myDemoX2=demoX ( )
  295.   currentMark=1
  296. endif
  297. goto MARK
  298.  
  299. label MARK
  300. demo Red
  301. demo Dashed line
  302. demo Line width... 2
  303. demo Draw line... myDemoX1 0 myDemoX1 5000
  304. demo Draw line... myDemoX2 0 myDemoX2 5000
  305. goto WAIT
  306.  
  307. label ANALYZE
  308. demo Undo
  309. #printline analyze 'myDemoX1' 'myDemoX2'
  310. # check
  311. if myDemoX1 == 0 || myDemoX2 == 0
  312.   goto WAIT
  313. endif
  314. if (myDemoX1 < myDemoX2)
  315.   mySamp1 = floor(myDemoX1 * 200)
  316.   mySamp2 = ceiling(myDemoX2 * 200)
  317. else
  318.   mySamp1 = floor(myDemoX2 * 200)
  319.   mySamp2 = ceiling(myDemoX1 * 200)
  320. endif
  321. select 'tor2'
  322. tor3=Extract row ranges... 'mySamp1':'mySamp2'
  323. t2=To Table...
  324. Append column... labelColumn
  325. nRow=Get number of rows
  326. for i from 1 to nRow
  327.   Set string value... i labelColumn +
  328. endfor
  329. Set string value... 1 labelColumn S
  330. Set string value... nRow labelColumn E
  331.  
  332. # plot
  333. Blue
  334. Scatter plot... 'ttChX$' artX1 artX2 'ttChZ$' artY1 artY2 labelColumn 12 'garnish$'
  335. garnish$="no"
  336. Red
  337. Scatter plot... 'tdChX$' artX1 artX2 'tdChZ$' artY1 artY2 labelColumn 12 'garnish$'
  338. Green
  339. Scatter plot... 'ulChX$' artX1 artX2 'ulChZ$' artY1 artY2 labelColumn 12 'garnish$'
  340. Purple
  341. Scatter plot... 'llChX$' artX1 artX2 'llChZ$' artY1 artY2 labelColumn 12 'garnish$'
  342.  
  343. ttxMed=Get quantile... 'ttChX$' 0.5
  344. ttzMed=Get quantile... 'ttChZ$' 0.5
  345. tdxMed=Get quantile... 'tdChX$' 0.5
  346. tdzMed=Get quantile... 'tdChZ$' 0.5
  347. ulxMed=Get quantile... 'ulChX$' 0.5
  348. ulzMed=Get quantile... 'ulChZ$' 0.5
  349. llxMed=Get quantile... 'llChX$' 0.5
  350. llzMed=Get quantile... 'llChZ$' 0.5
  351. time1=mySamp1/200
  352. time2=mySamp2/200
  353. printline 'time1:3''tab$''time2:3''tab$''ttxMed:3''tab$''ttzMed:3''tab$''tdxMed:3''tab$''tdzMed:3''tab$''ulxMed:3''tab$''ulzMed:3''tab$''llxMed:3''tab$''llzMed:3'
  354. fileappend 'logName$' 'time1:3''tab$''time2:3''tab$''ttxMed:3''tab$''ttzMed:3''tab$''tdxMed:3''tab$''tdzMed:3''tab$''ulxMed:3''tab$''ulzMed:3''tab$''llxMed:3''tab$''llzMed:3''newline$'
  355.  
  356.  
  357.  
  358. analyzed=analyzed+1
  359.  
  360. plus 'tor3'
  361. Remove
  362. goto WAIT
  363.  
  364. procedure split .str$ .delimiter$
  365.   .num = 1
  366.   .arr$[.num] = .str$
  367.   repeat
  368.     .lastValue$ = .arr$[.num]
  369.     .delimiterPos = index_regex(.lastValue$,.delimiter$)
  370.     if .delimiterPos <> 0
  371.       .arr$[.num] = left$(.lastValue$,.delimiterPos-1)
  372.       .num += 1
  373.       .arr$[.num] = replace_regex$(right$(.lastValue$,length(.lastValue$)-.delimiterPos+1),.delimiter$,"",1)
  374.     endif
  375.   until .delimiterPos = 0
  376. endproc

Screenshots (on google drive)


Reaction time analyzer

Reaction time analyzer


Script used to estimate voice activity. Use of the demo window to run through lots of files. Some tricks to detect steepest rise.

  1. #form Reaction time analyzer
  2. # sentence majorPath C:\Users\ling-jfr\Dropbox\Atttittapådata
  3. # natural currentSweep 1
  4. #endform
  5.  
  6. # commented to get sane syntax highlighing in the wiki
  7. #majorPath$="C:\Users\ling-jfr\Dropbox\Atttittapådata"
  8. ##anaFile$="C:\Users\ling-jfr\Dropbox\Atttittapådata\analysis.txt"
  9. #anaFile$="C:\Users\ling-jfr\Documents\Praat\analysis.txt"
  10. createAnalysisFile=0
  11.  
  12. nocheck select all
  13. nocheck Remove
  14. Erase all
  15. #clearinfo
  16.  
  17. currentSweep=1
  18. # find unanalyzed
  19. if fileReadable(anaFile$)
  20.   anaStrings=Read from file... 'anaFile$'
  21.   numStr=Get number of strings
  22.   for i from 1 to numStr
  23.     cStr$=Get string... i
  24.     if cStr$=="false"
  25.       currentSweep=i
  26.       i=numStr
  27.     endif
  28.   endfor
  29. endif
  30. #currentSweep=1
  31.  
  32. wavTop=95
  33. wavBottom=65
  34. specTop=70
  35. specBottom=40
  36. garnish$="yes"
  37. analyzed=0
  38.  
  39. # commented to get sane syntax highlighing in the wiki
  40. #if windows
  41. #  separator$ = "\"
  42. #else
  43. #  separator$ = "/"
  44. #endif
  45.  
  46. timeRange1=0
  47. timeRange2=0
  48.  
  49. # create notch filter
  50. #lowSteep = sqrt(ln(2))
  51. #lowFreq = 430
  52. #beta = sqrt(ln(2))
  53. #highFreq = 2000
  54. #filterSound=Create Sound from formula... filter 1 -0.2 0.2 44100 2*pi*sqrt(pi)*highFreq/beta*exp(-(pi*x*highFreq/beta)^2) - 4*pi*sqrt(pi)*lowFreq/lowSteep*exp(-(pi*x*lowFreq/lowSteep)^2)
  55.  
  56. # lpc filter
  57. lpcfilter=Read from file... C:\Users\ling-jfr\Dropbox\Atttittapådata\lpcfilter.LPC
  58.  
  59. # run through dir and subdirs and look for wavs
  60. # store them in Strings object wavStrings
  61. dirWithWavs=0
  62. dirGlobPath$=majorPath$+separator$+"*"
  63. strings1 = Create Strings as directory list... directoryList1 'dirGlobPath$'
  64. nStrings1=Get number of strings
  65. for i from 1 to nStrings1
  66.   select 'strings1'
  67.   currentStringi$=Get string... i
  68.   subDirGlobPath$=majorPath$+separator$+currentStringi$
  69.   strings2 = Create Strings as directory list... directoryList2 'subDirGlobPath$'
  70.   nStrings2=Get number of strings
  71.   for j from 1 to nStrings2
  72.     select 'strings2'
  73.     currentStringj$=Get string... j
  74.     wavGlobPath$=subDirGlobPath$+separator$+currentStringj$+separator$+"*.wav"
  75.     strings3 = Create Strings as file list... fileList 'wavGlobPath$'
  76.     nStrings3=Get number of strings
  77.     for k from 1 to nStrings3
  78.       select 'strings3'
  79.       currentStringk$=Get string... k
  80.       wavName$=subDirGlobPath$+separator$+currentStringj$+separator$+currentStringk$
  81.       Set string... k 'wavName$'
  82.     endfor
  83.  
  84.     if nStrings3 > 0
  85.       dirWithWavs=dirWithWavs+1
  86.     endif
  87.     if dirWithWavs==1
  88.       select 'strings3'
  89.       Copy... appended
  90.       wavStrings=selected("Strings")
  91.     endif
  92.     if dirWithWavs > 1
  93.       select 'wavStrings'
  94.       plus 'strings3'
  95.       newWavStrings=Append
  96.       select 'wavStrings'
  97.       Remove
  98.       select 'newWavStrings'
  99.       wavStrings=selected("Strings")
  100.     endif
  101.     select 'strings3'
  102.     Remove
  103.   endfor
  104.   select 'strings2'
  105.   Remove
  106. endfor
  107. select 'strings1'
  108. Remove
  109.  
  110. select 'wavStrings'
  111. numWav=Get number of strings
  112. # we should save the wavStrings with the anaFile so
  113. # we're safe if the wav structure is changed
  114.  
  115. # create an analysis file
  116. if createAnalysisFile
  117.   for i from 1 to numWav
  118.     Set string... i false
  119.   endfor
  120.   Save as short text file... 'anaFile$'
  121.   exit
  122. endif
  123.  
  124. goto GETDATA
  125.  
  126. label CLEANDATA
  127. select 's1'
  128. plus 's2'
  129. plus 's4'
  130. plus 'spec1'
  131. plus 'i1'
  132. plus 'tg1'
  133. Remove
  134. goto GETDATA
  135.  
  136. label GETDATA
  137. select 'wavStrings'
  138. currentStringi$=Get string... currentSweep
  139. s1=Read from file... 'currentStringi$'
  140. startSound = Get start time
  141. endSound = Get end time
  142. startIv = startSound
  143. endIv = endSound
  144. durIv = endIv - startIv
  145. plus 'lpcfilter'
  146. s4=Filter (inverse)
  147. Scale intensity... 70
  148. spec1=noprogress To Spectrogram... 0.005 5000 0.002 20 Gaussian
  149. select 's4'
  150. s2=noprogress Deepen band modulation... 20 300 8000 3 30 100
  151. Scale intensity... 70
  152.  
  153. select 's2'
  154. i1=To Intensity... 75 0 yes
  155. Formula... if x < 0.2 || x > 1.5 then 0 else self fi
  156.  
  157. keep = 0
  158. noMoreCheck = 0
  159. numberOfLevels = 5
  160. for i from 1 to numberOfLevels
  161.   thresh = -5-(i*5)
  162.   select 'i1'
  163.   tg'i' = To TextGrid (silences)... thresh 0.1 0.12 silent sounding
  164.   countSounding=Count labels... 1 sounding
  165.   if countSounding > 1 && keep > 0
  166.     noMoreCheck=1  
  167.   endif
  168.   if countSounding == 1 && noMoreCheck == 0
  169.     if i > 1
  170.       lastDurIv = durIv
  171.     endif
  172.     call GetBounds
  173.     if i > 1
  174.       tIncrease = durIv / lastDurIv
  175.     else
  176.       tIncrease = 1
  177.     endif
  178.     keep = i
  179.  
  180. #  # prevent overlong increase between 20 and 25
  181. #  if i == 4
  182. #   printline overlong increase 'currentSweep' 'i': ('tIncrease')
  183. #   if tIncrease > 1.25
  184. #    keep = 3
  185. #    noMoreCheck = 1
  186. #    printline overlong increase 'currentSweep' 'i': ('tIncrease')
  187. #   else
  188. #    keep = 4
  189. #   endif
  190. #  endif
  191.  
  192.  
  193.     # prevent overlong increase between 25 and 30
  194.     if i == 5
  195.       if tIncrease > 1.5
  196.         keep = 4
  197.         noMoreCheck = 1
  198. #    printline overlong increase 'currentSweep' 'i': ('tIncrease')
  199.       else
  200.         keep = 5
  201.       endif
  202.     endif
  203.   endif
  204. endfor
  205.  
  206. if keep > 0
  207.   dum = tg'keep'
  208.   select 'dum'
  209.   tgfin = Copy...
  210. else
  211.   select 'i1'
  212.   tgfin = To TextGrid (silences)... -200 0.1 0.1 silent sounding
  213. endif
  214.  
  215. select 'tg1'
  216. for i from 2 to numberOfLevels
  217.   dum = tg'i'
  218.   plus 'dum'
  219. endfor
  220. Remove
  221.  
  222. select 'tgfin'
  223. tg1=selected("TextGrid")
  224.  
  225. select 'i1'
  226. call findRise
  227. tg2=selected("TextGrid")
  228. plus 'tg1'
  229. tgboth=Merge
  230. select 'tg1'
  231. plus 'tg2'
  232. Remove
  233. select 'tgboth'
  234. tg1=selected("TextGrid")
  235.  
  236.  
  237. startIv = startSound
  238. endIv = endSound
  239. durIv = endIv - startIv
  240. call GetBounds
  241. goto REDRAW
  242.  
  243. procedure GetBounds
  244. #indent
  245. nInt=Get number of intervals... 1
  246. for .i from 1 to nInt
  247.   lab$=Get label of interval... 1 .i
  248.   if lab$=="sounding"
  249.     startIv=Get start point... 1 .i
  250.     endIv=Get end point... 1 .i
  251.     durIv = endIv - startIv
  252.   endif
  253. endfor
  254. select 'i1'
  255. dbAtStartIv=Get value at time... startIv Cubic
  256. #indent
  257. endproc
  258.  
  259.  
  260. label REDRAW
  261. demo Erase all
  262. demo Select outer viewport... 0 100 0 100
  263. demo Axes... 0 100 0 100
  264. demo Black
  265. demo Line width... 1
  266. demo Solid line
  267.  
  268. # Title
  269. demo Text... 50 centre 100 top 'currentStringi$' ('currentSweep'/'numWav')
  270.  
  271. # buttons
  272. call DrawButton 0 20 12 18 Prev
  273. call DrawButton 25 45 12 18 Reject
  274. call DrawButton 50 70 12 18 Accept
  275. call DrawButton 75 95 12 18 Next
  276.  
  277. call DrawButton 12 32 24 30 Target
  278. call DrawButton 37 58 28 34 Before
  279. call DrawButton 37 58 20 26 After
  280. call DrawButton 63 83 24 30 All
  281.  
  282. procedure DrawButton .leftX .rightX .topY .bottomY .buttonText$
  283.   demo Paint rectangle... pink .leftX .rightX .topY .bottomY
  284.   demo Draw rectangle... .leftX .rightX .topY .bottomY
  285.   .textX = (.rightX + .leftX) / 2
  286.   .textY = (.topY + .bottomY) / 2
  287.   demo Text... .textX centre .textY half '.buttonText$'
  288. endproc
  289.  
  290. # waveform
  291. demo Select outer viewport... 0 100 'wavBottom' 'wavTop'
  292. select 's4'
  293. plus 'tg1'
  294. demo Draw... timeRange1 timeRange2 yes yes yes
  295. demo Red
  296. demo Solid line
  297. demo Line width... 3
  298. demo Draw rounded rectangle... startIv endIv 1 -1 3
  299. demo Line width... 1
  300.  
  301. # spectrogram
  302. demo Select outer viewport... 0 100 'specBottom' 'specTop'
  303. select 'spec1'
  304. demo Paint... timeRange1 timeRange2 0 0 100 yes 50 6 0 yes
  305. select 'i1'
  306. demo Line width... 2
  307. demo Draw... timeRange1 timeRange2 0 0 no
  308.  
  309. myDemoX1=timeRange1
  310. myDemoX2=timeRange1
  311. currentMark=1
  312. goto WAIT
  313.  
  314. label WAIT
  315. while demoWaitForInput ( )
  316.   if demoClicked ( )
  317.     demo Select outer viewport... 0 100 0 100
  318.     demo Axes... 0 100 0 100
  319.     goto PREV demoClickedIn (0, 20, 12, 18)
  320.     goto REJECT demoClickedIn (25, 45, 12, 18)
  321.     goto ACCEPT demoClickedIn (50, 70, 12, 18)
  322.     goto NEXT demoClickedIn (75, 95, 12, 18)
  323.  
  324.     goto PLAYTARGET demoClickedIn (12, 32, 24, 30)
  325.     goto PLAYBEFORE demoClickedIn (37, 58, 28, 34)
  326.     goto PLAYAFTER demoClickedIn (37, 58, 20, 26)
  327.     goto PLAYALL demoClickedIn (63, 83, 24, 30)
  328.  
  329.     #demo Undo
  330.  
  331.     #demo Select outer viewport... 0 100 'specBottom' 'specTop'
  332.     #demo Axes... 0 'soundDur' 0 5000
  333.     #goto GETMOUSEX demoClickedIn (0, soundDur, 0, 5000)
  334.     #demo Undo
  335.   endif
  336.   #goto GETMOUSEX demoClickedIn (0, soundDur, 0, 5000)
  337.   #goto PLAY demoClickedIn
  338.   #goto MARKLEFT demoInput ("1")
  339.   #goto MARKRIGHT demoInput ("2")
  340.   goto EXIT demoInput ("x")
  341.   goto ACCEPT demoInput (" ")
  342.   goto REJECT demoInput ("r")
  343.   goto PLAYTARGET demoInput ("t")
  344.   goto PLAYALL demoInput ("a")
  345.   goto ERROR demoInput("e")
  346. endwhile
  347. pause Why are we here?
  348.  
  349. label ACCEPT
  350. select 'anaStrings'
  351. Set string... currentSweep 'startIv:3'
  352. Save as short text file... 'anaFile$'
  353. goto NEXT
  354.  
  355. label REJECT
  356. select 'anaStrings'
  357. Set string... currentSweep reject
  358. Save as short text file... 'anaFile$'
  359. goto NEXT
  360.  
  361. label ERROR
  362. select 'anaStrings'
  363. Set string... currentSweep error
  364. Save as short text file... 'anaFile$'
  365. goto NEXT
  366.  
  367. label NEXT
  368. #demo Undo
  369. currentSweep=currentSweep+1
  370. goto CLEANDATA
  371.  
  372. label PREV
  373. #demo Undo
  374. currentSweep=currentSweep-1
  375. goto CLEANDATA
  376.  
  377. label EXIT
  378. demo Select outer viewport... 0 100 0 100
  379. demo Axes... 0 100 0 100
  380. demo Text... 50 centre 0 bottom Script has finished. Please close this window manually...
  381. exit
  382.  
  383. label PLAYTARGET
  384. startPlay = startIv
  385. endPlay = endIv
  386. goto PLAY
  387.  
  388. label PLAYBEFORE
  389. startPlay = startSound
  390. endPlay = startIv
  391. goto PLAY
  392.  
  393. label PLAYAFTER
  394. startPlay = endIv
  395. endPlay = endSound
  396. goto PLAY
  397.  
  398. label PLAYALL
  399. startPlay = startSound
  400. endPlay = endSound
  401. goto PLAY
  402.  
  403. label PLAY
  404. select 's4'
  405. s3=Extract part... startPlay endPlay rectangular 1 no
  406. Play
  407. Remove
  408. goto WAIT
  409.  
  410. # unused
  411. procedure useVoicing
  412. select 's2'
  413. pp1=noprogress To PointProcess (periodic, cc)... 75 600
  414. tg2=To TextGrid (vuv)... 0.02 0.01
  415. nInt=Get number of intervals... 1
  416. myLowest=100
  417. moveTo=0
  418. for i from 1 to nInt
  419.   lab$=Get label of interval... 1 i
  420.   if lab$=="V"
  421.     startVIv=Get start point... 1 i
  422.     diff=abs(startIv-startVIv)
  423.     if diff < myLowest
  424.       myLowest = diff
  425.       moveTo=startVIv
  426.     endif 
  427.   endif
  428. endfor
  429. startIv=moveTo
  430.  
  431. plus 'tg1'
  432. tgboth=Merge
  433. select 'tg1'
  434. plus 'tg2'
  435. plus 'pp1'
  436. Remove
  437. select 'tgboth'
  438. tg1=selected("TextGrid")
  439. endproc
  440.  
  441.  
  442. procedure findRise
  443.   .i1=selected("Intensity")
  444.   .m1=Down to Matrix
  445.   .s1=To Sound
  446.   .pp1=To PointProcess (extrema)... 1 yes no Sinc70
  447.   select '.i1'
  448.   #call Acceleration
  449.   call Curvature
  450.   #call Velocity
  451.   .s2=selected("Sound")
  452.   .pp2=To PointProcess (extrema)... 1 yes no Sinc70
  453. if 1
  454.   np1=Get number of points
  455.   candidateIndex=0
  456.   for cp1 from 1 to np1
  457.     select '.pp2'
  458.     accStartTime=Get time from index... cp1
  459.     if accStartTime > 0.2 && accStartTime < 1.5
  460.     select '.pp1'
  461.     disPeakIndex=Get high index... accStartTime
  462.     if disPeakIndex = undefined
  463.       # some exceptional action
  464.     else
  465.       disPeakTime=Get time from index... disPeakIndex
  466.       if disPeakTime = undefined
  467.         # some exceptional action
  468.       else
  469.         candidateIndex=candidateIndex+1
  470.         select '.i1'
  471.         accStartVal=Get value at time... accStartTime Cubic
  472.         disPeakVal=Get value at time... disPeakTime Cubic
  473.         valDiff=disPeakVal-accStartVal
  474.         #printline AccIndex: 'cp1' DisPeakIndex: 'disPeakIndex'
  475.         # ... AccStartTime: 'accStartTime:3' DisPeakTime: 'disPeakTime:3'
  476.         # ... AccStartVal: 'accStartVal:3' DisPeakVal: 'disPeakVal:3'
  477.         # ... ValDiff: 'valDiff:3'
  478.         sTime'candidateIndex'=accStartTime
  479.         eTime'candidateIndex'=disPeakTime 
  480.         valD'candidateIndex'=valDiff
  481.       endif
  482.     endif
  483.     endif
  484.   endfor
  485. endif
  486.  
  487.  
  488. if 1
  489.   max=0
  490.   indexOfMax=0
  491.   for cCand from 1 to candidateIndex
  492.     if valD'cCand'>=max
  493.       max = valD'cCand'
  494.       indexOfMax=cCand
  495.     endif
  496.   endfor
  497.   select '.s1'
  498.   .tg1=To TextGrid... rise
  499.   Insert boundary... 1 sTime'indexOfMax'
  500.   Insert boundary... 1 eTime'indexOfMax'
  501.   Set interval text... 1 2 rise
  502. endif
  503.  
  504.   select '.pp2'
  505.   plus '.s2'
  506.   plus '.pp1'
  507.   plus '.s1'
  508.   plus '.m1'
  509.   Remove
  510.   select '.tg1'
  511. endproc
  512.  
  513. procedure Curvature
  514.   .m1=Down to Matrix
  515.   Rename... '.m1'
  516.   .m2=Copy... Velocity
  517.   Rename... '.m2'
  518.   Formula... (Matrix_'.m1'[col+1]-Matrix_'.m1'[col-1])/2*dx
  519.   Formula... if col == 1 || col == ncol then 0 else self fi
  520.   .m3=Copy... Acceleration
  521.   Rename... '.m3'
  522.   Formula... (Matrix_'.m2'[col+1]-Matrix_'.m2'[col-1])/2*dx
  523.   Formula... if col == 1 || col == ncol then 0 else self fi
  524.   select '.m1'
  525.   Formula... Matrix_'.m3'[col]/(1+Matrix_'.m2'[col]^2)^1.5
  526.   .s1=To Sound
  527.   Rename... '.s1'
  528.   select '.m1'
  529.   plus '.m2'
  530.   plus '.m3'
  531.   Remove
  532.   select '.s1'
  533. endproc

Screenshot (at google drive)


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

Syllabifier

This is somewhat mad: first do phone recognition using sphinx, then syllabify using syllabify.py. Works pretty well, even for Swedish!

There were a few hurdles in getting sphinx to run, but it boiled down to using the correct version of sphinxbase and sphinx3 as mentioned here.

I built my own language model using lmtool, see info here. This was based on ked_timit + some of the arctic databases. This seems to work better for short sentences of read-type speech.

  1. #nocheck select all
  2. #nocheck Remove
  3.  
  4. sphinxDir$="~/OperaDownloads/sphinxtest/"
  5. phonesTier=1
  6. sylTier=2
  7.  
  8. include ~/.praat-dir/split.proc.praat
  9.  
  10. s1 = selected("Sound")
  11. #s1=do ("Read from file...", sphinxDir$+"in.sph")
  12.  
  13. do ("Save as NIST file...", sphinxDir$+"test.sph")
  14. tg1=do ("To TextGrid...", "sphinx_seg sylls", "")
  15.  
  16. system sphinx3_decode
  17. ... -mode allphone
  18. ... -ctl 'sphinxDir$'test.ctl
  19. ... -cepdir 'sphinxDir$'
  20. ... -cepext .sph
  21. ... -adcin yes
  22. ... -adchdr 1024
  23. ... -hmm /home/johanf/OperaDownloads/sphinx3-0.8/model/hmm/hub4_cd_continuous_8gau_1s_c_d_dd
  24. ... -lm 'sphinxDir$'7035.lm
  25. ... -dict 'sphinxDir$'7035.dic
  26. ... -fdict 'sphinxDir$'filler.dict
  27. ... -hypseg 'sphinxDir$'test.lab
  28.  
  29. #... -lm 'sphinxDir$'7666.lm
  30. #... -lm 'sphinxDir$'interp_nodx.arpa.dmp
  31. # we build our own lm from cmudict
  32.  
  33.  
  34. str1=do ("Read Strings from raw text file...", sphinxDir$+"test.lab")
  35. sphinx_str$=Get string... 1
  36.  
  37. select 'tg1'
  38.  
  39. writeInfoLine("--sphinx output--")
  40. @split (" ", sphinx_str$)
  41.  
  42. #for i to split.length
  43. # str$[i] = split.array$[i]
  44. # appendInfoLine(i, tab$, str$[i])
  45. #endfor
  46.  
  47. co=13
  48. labNo=0
  49. sylString$=""
  50. while co < split.length
  51.   lab$ = split.array$[co]
  52.   #if (lab$ != "SIL")
  53.     sylString$=sylString$+lab$+" "
  54.   #endif
  55.   frame = number(split.array$[co+1])*0.01
  56.  
  57.   labNo=labNo+1
  58.   do ("Insert boundary...", phonesTier, frame)
  59.   do ("Set interval text...", phonesTier, labNo, lab$)
  60.  
  61. # # if first is SIL then add sylbound at end of interval
  62. # if (labNo==1)
  63. #  do ("Insert boundary...", sylTier, frame)
  64. # endif
  65.  
  66.   appendInfoLine(co, tab$, lab$, tab$, frame)
  67.   co = co + 4
  68. endwhile
  69. # if last is SIL then keep a reminder to add sylbound at start of interval
  70. #addLast=0
  71. if (lab$ == "SIL")
  72. # addLast=1
  73.   addLastTime=do ("Get start point...", phonesTier, labNo)
  74. else
  75.   addLastTime=do ("Get end point...", phonesTier, labNo)
  76. endif
  77.  
  78. writeFile(sphinxDir$+"phones.txt", sylString$)
  79.  
  80. system python 'sphinxDir$'syllabifier.py English < 'sphinxDir$'phones.txt > 'sphinxDir$'syllables.txt
  81. syllables$ = readFile$ (sphinxDir$+"syllables.txt")
  82. appendInfoLine(syllables$)
  83. @split (" ", syllables$)
  84.  
  85. sylIndex=0
  86. for i to split.length
  87.   if (split.array$[i] == "SIL" && i == 1)
  88.     sylTime=do ("Get end point...", phonesTier, 1)
  89.     do ("Insert boundary...", sylTier, sylTime)
  90.   endif
  91.   if (split.array$[i] == ".")
  92.     sylIndex=sylIndex+1
  93.     phoneWithSyl = i - sylIndex
  94.     sylTime=do ("Get end point...", phonesTier, phoneWithSyl)
  95.     do ("Insert boundary...", sylTier, sylTime)
  96.     nInt=do ("Get number of intervals...", sylTier)
  97.     do ("Set interval text...", sylTier, nInt-1, "syl")
  98.   endif
  99. endfor
  100. #if (addLast)
  101.   do ("Insert boundary...", sylTier, addLastTime)
  102.   nInt=do ("Get number of intervals...", sylTier)
  103.   do ("Set interval text...", sylTier, nInt-1, "syl")
  104. #endif 
  105.  
  106.  
  107. plusObject (s1)

Vowels


Warp duration

How to warp (stretch and compress) the durations of the segments of one version of an utterance to mimic those of another version of the same utterance.

  1. s1 = selected("Sound",1)
  2. s2 = selected("Sound",2)
  3. s1$ = selected$("Sound",1)
  4. s2$ = selected$("Sound",2)
  5.  
  6. select 's2'
  7. Copy...
  8. Rename... 's1$'_into_'s2$'
  9. s2n = selected("Sound")
  10. Formula... 0
  11. sr = Get sampling frequency
  12. winlen = 0.032
  13. hwinlen = winlen/2
  14. dx = 0.01532
  15.  
  16. select 's1'
  17. plus 's2'
  18. To MFCC... 12 'winlen' 'dx' 100 100 0
  19. mfcc1 = selected("MFCC",1)
  20. mfcc2 = selected("MFCC",2)
  21. minus 'mfcc1'
  22. x1 = Get time from frame number... 1
  23. dur = Get total duration
  24. ct = x1
  25.  
  26. plus 'mfcc1'
  27. To DTW... 1 0 0 0 0.056 yes yes 2/3 < slope < 3/2
  28. dtw1 = selected("DTW")
  29.  
  30. frn=0
  31. while ct < dur
  32.   frn=frn+1
  33.   pt = Get time along path... 'ct' Highest
  34.   pt'frn' = pt+randomGauss(0,0.00001)
  35.   ct=ct+dx
  36. endwhile
  37.  
  38. ct = x1
  39. for i from 1 to frn
  40.   select 's1'
  41.   pt=pt'i'
  42.   sw=pt-hwinlen
  43.   ew=pt+hwinlen
  44.   Extract part... 'sw' 'ew' Gaussian1 1 no
  45.   s3=selected("Sound")
  46.   Rename... 's3' 
  47.  
  48.   swt=ct-hwinlen
  49.   ewt=ct+hwinlen
  50.   ct=ct+dx
  51.   stsamp = round(swt*sr)
  52.   ensamp = round(ewt*sr)
  53.  
  54.   select 's2n'
  55.   Formula... if col > stsamp && col <= ensamp then self+Sound_'s3'_[col-stsamp] else self fi
  56.  
  57.   select 's3'
  58.   Remove
  59. endfor

Warp duration using Psola

How to warp (stretch and compress) the durations of the segments of one version of an utterance to mimic those of another version of the same utterance.

  1. minp=50
  2. maxp=200
  3. winlen = 0.025
  4. tstep = 0.01
  5.  
  6. s1 = selected("Sound",1)
  7. #tg1 = selected("TextGrid",1)
  8. s2 = selected("Sound",2)
  9.  
  10. select 's1'
  11. To PointProcess (periodic, cc)... 'minp' 'maxp'
  12. To TextGrid (vuv)... 0.02 0.01
  13. tg1 = selected("TextGrid",1)
  14.  
  15. select 's1'
  16. Copy...
  17. s1n = selected("Sound")
  18. dur1 = Get total duration
  19. plus 's2'
  20. To MFCC... 12 'winlen' 'tstep' 100 100 0
  21. mfcc2 = selected("MFCC",1)
  22. mfcc1 = selected("MFCC",2)
  23.  
  24. # include log energy
  25. To DTW... 0.9230769230769231 0.07692307692307693 0 0 0.056 yes yes 1/3 < slope < 3
  26. Find path (band)... 0.1 yes 1 1 2
  27. #To DTW... 1 0 0 0 0.056 yes yes 1/3 < slope < 3
  28. dtw1 = selected("DTW")
  29.  
  30. select 'tg1'
  31. ni = Get number of intervals... 1
  32. for i to ni
  33.   tim'i' = Get end point... 1 'i'
  34.   lab'i'$ = Get label of interval... 1 'i'
  35. endfor
  36.  
  37. select 'dtw1'
  38. lastt = 0
  39. lastnt = 0
  40. for i to ni
  41.   t = tim'i'
  42.   lpt = Get time along path... 't' Lowest
  43.   hpt = Get time along path... 't' Highest
  44.   nt'i' = (lpt+hpt)/2
  45.   lab$ = lab'i'$
  46.   nt = nt'i'
  47.   durt=t-lastt
  48.   durnt=nt-lastnt
  49.   stretch'i'=durnt/durt
  50.   stretch = stretch'i'
  51.   printline Interval 'lab$' should be stretched 'stretch''tab$'('lastt:3','t:3','durt:3') -> ('lastnt:3','nt:3','durnt:3').
  52.   lastt = t
  53.   lastnt = nt
  54. endfor
  55.  
  56. Create DurationTier... empty 0 dur1
  57. lastt = 0
  58. for i to ni
  59.   str = stretch'i'
  60.   p1 = lastt+0.001
  61.   p2 = tim'i'-0.001
  62.  
  63.   #mp = (p2+p1)/2
  64.   #Add point... mp str
  65.  
  66.   Add point... p1 str
  67.   Add point... p2 str
  68.  
  69.   printline 'p1' 'p2' 'str'
  70.   lastt = tim'i'
  71. endfor
  72. dt1=selected("DurationTier")
  73. select 's1'
  74. To Manipulation... 0.01 'minp' 'maxp'
  75. man1=selected("Manipulation")
  76. plus 'dt1'
  77. Replace duration tier
  78. select 'man1'
  79. Get resynthesis (PSOLA)

November 2014
MonTueWedThuFriSatSun
     0102
03040506070809
10111213141516
17181920212223
24252627282930