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

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

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)

June 2013
MonTueWedThuFriSatSun
     0102
03040506070809
10111213141516
17181920212223
24252627282930