#Autoseg 2.0 by SHUO ZHANG #updated 2/15/13 #exclusively for Setswana Project word lists #this version: works for any number of repetition in the word list, either 2,3,4, or any other number #no marking voicing and F0-F1 values #prefix=w1, word=w2, both on word tier #preceding1=s1,preceding2=s2,consonant3=w3,vowel4=s4, on segment tier form Get duration data comment Please input duration data comment e.g., on word tier, w1=xo, w2=baka comment e.g., on segment tier, s1=x, s2=o, s3=b, s4=a real w1 0.160 real w2 0.390 real s1 0.082 real s2 0.081 real s3 0.125 real s4 0.109 comment Directory path to save the textfiles: comment Example (PC): C:\documents and settings\(username)\desktop\Textgrids\ comment Example (Mac): /Users/miep/Desktop/Textgrids/ comment PC users: to use the default path, create a "Textgrids" folder on desktop comment And subsitute your username in the path comment Mac users: to use the sample path from above (Mac), create a "Textgrids" folder on desktop text output_directory ~/Desktop/Textgrids/ endform w1=0.160 w2=0.390 s1=0.082 s2=0.081 s3=0.125 s4=0.109 n=numberOfSelected ("Sound") echo n='n' for i to n sound'i' = selected ("Sound", i) printline sound'i' endfor printline printline if number of intervals is even number, the file is noisy: for i to n select sound'i' label$=selected$ ("Sound") #create a textgrid and segment the individual repetitions intensity=To Intensity... 80 0 select intensity textgrid=To TextGrid (silences)... -25.0 0.3 0.1 "" 'label$' select intensity Remove select textgrid p=Get number of intervals... 1 m=(p-1)/2 #m is the number of repetition #resegmentation: #if the label of first interval!="", then add silence in the beginning (procedure ReSegment_B) #if the label of last interval!="", then add silence in the end(procedure ReSegment_E) #if both labels != "", then add silence in both(procedure ReSegment_BE) begin$=Get label of interval... 1 1 end$=Get label of interval... 1 p printline --------------------------- printline 'label$' printline number of interval of tier 1: 'p' printline label of first interval on tier 1: 'begin$' printline label of last interval on tier 1: 'end$' if (begin$!="") and (end$!="") call ReSegment_BE elsif begin$!="" call ReSegment_B elsif end$!="" call ReSegment_E endif #insert tiers select textgrid Insert interval tier... 2 Word Insert interval tier... 3 Segment Insert interval tier... 4 VOT Insert interval tier... 5 Voice/Burst #m is the number of repetition for j to m #get onset and end time of each repetition t01=Get starting point... 1 2*j t02=Get end point... 1 2*j #'xo' regressive segmentation d=1 letter$=mid$(label$,d,1) #checking how many letters is in the root of the word in file name while letter$!="_" d=d+1 letter$=mid$(label$,d,1) endwhile if mid$(label$,d+1,1)="x" t01=t01-0.09 Insert boundary... 1 t01 Remove right boundary... 1 2*j endif call insertBoundary t01 endfor select textgrid Write to text file... 'output_directory$''label$'.TextGrid endfor procedure insertBoundary t #copy word boundaries from tier 1 to tier 2 Insert boundary... 2 t Insert boundary... 2 t02 #time points of labelling t2=t+s1 t3=t2+s2 t4=t3+s3 t5=t4+s4 t6=t3+w2 c=1 letter$=mid$(label$,c,1) #checking how many letters is in the root of the word in file name while letter$!="_" c=c+1 letter$=mid$(label$,c,1) endwhile #check if the file name is of the correct type namecheck=index(label$, "_") if namecheck=0 exit ERROR!PLEASE MAKE SURE YOUR SOUND FILE IS CORRECTLY NAMED endif #isolation case iso$=mid$(label$,c+1,1) if ((iso$!="N") and (iso$!="x") and (iso$!="o")) s3=0.058 s4=0.212 t3=t t4=t3+s3 t5=t4+s4 Insert boundary... 3 t3 Insert boundary... 3 t4 Insert boundary... 3 t5 #set baka label on word tier l0$=left$(label$,c-1) Set interval text... 2 2*j 'l0$''j' #set /b/ and /a/ label on segment tier l1$=left$(label$,1) l2$=mid$(label$,2,1) Set interval text... 3 2+3*(j-1) 'l1$' Set interval text... 3 3*j 'l2$' #non-isolation case else #set prefix label on word and segment tiers if mid$(label$,c+1,1)="N" w1=0.22 t2=t+s1 t3=t+w1 t4=t3+s3 t5=t4+s4 t6=t3+w2 Insert boundary... 3 t2 Insert boundary... 3 t3 Insert boundary... 3 t4 Insert boundary... 3 t5 Insert boundary... 2 t6 Insert boundary... 2 t3 Insert boundary... 3 t Set interval text... 3 2+5*(j-1) \hs Set interval text... 2 2+4*(j-1) N Set interval text... 3 3+5*(j-1) m l1$=left$(label$,1) l2$=mid$(label$,2,1) Set interval text... 3 4+5*(j-1) 'l1$' Set interval text... 3 5*j 'l2$' endif if mid$(label$,c+1,1)="x" w1=0.24 s1=0.1 s4=0.09 t2=t+s1 t3=t2+s2 t4=t3+s3 t5=t4+s4 t6=t3+w2 Insert boundary... 3 t2 Insert boundary... 3 t3 Insert boundary... 3 t4 Insert boundary... 3 t5 Insert boundary... 2 t6 Insert boundary... 2 t3 Set interval text... 2 2+4*(j-1) xo Set interval text... 3 2+4*(j-1) o l1$=left$(label$,1) l2$=mid$(label$,2,1) Set interval text... 3 3+4*(j-1) 'l1$' Set interval text... 3 4*j 'l2$' endif if mid$(label$,c+1,1)="o" w1=0.25 t2=t+s1 t3=t+w1 t4=t3+s3 t5=t4+s4 t6=t3+w2 Insert boundary... 3 t2 Insert boundary... 3 t3 Insert boundary... 3 t4 Insert boundary... 3 t5 Insert boundary... 2 t6 Insert boundary... 2 t3 Set interval text... 2 2+4*(j-1) ore Set interval text... 3 2+4*(j-1) \ic l1$=left$(label$,1) l2$=mid$(label$,2,1) Set interval text... 3 3+4*(j-1) 'l1$' Set interval text... 3 4*j 'l2$' endif #set baka label on word tier l0$=left$(label$,c-1) Set interval text... 2 3+4*(j-1) 'l0$''j' Set interval text... 2 4*j xape endif endproc #resegmentation: #if the label of first interval!="", then add silence in the beginning (procedure ReSegment_B) #if the label of last interval!="", then add silence in the end(procedure ReSegment_E) #if both labels != "", then add silence in both(procedure ReSegment_BE) procedure ReSegment_B printline 'label$' select textgrid Remove #fixing the incorrect labelling caused by the noisy beginning of sound file: #create a silence sound of 1s (sound 1) #get the duration of the sound file #extract the sound file to create a new sound file with the duration of the original sound file (sound 2) #combine sound 1 and sound 2=a sound 3 with 1s of silence in the beginning, ensure that the onset of the first interval on the first tier is not identical to the 0.00s in sound file #rename sound 3 as the original sound name #save sound 3 as the original sound name in its original folder #delete the original sound #delete sound 1 and sound 2 #select sound 3,now named the same as the original sound, redo the segmentation on tier 1 select sound'i' sampling_frequency = Get sampling frequency duration = Get total duration #extract part... is a function available for Sound objects, in the Convert... menu. not to be confused with Index:Extract Part... in the praat help menu. mySilence = Create Sound from formula... silence 1 0 1 sampling_frequency 0 select sound'i' myEnd = Extract part... 0 duration rectangular 1 no select mySilence plus myEnd myNewSound = Concatenate select sound'i' plus mySilence plus myEnd Remove select myNewSound Rename... 'label$' Save as WAV file... 'output_directory$''label$'.wav #redo segmentation once select myNewSound intensity=To Intensity... 80 0 select intensity textgrid=To TextGrid (silences)... -25.0 0.3 0.1 "" 'label$' select intensity Remove printline this sound file fixed select textgrid p=Get number of intervals... 1 begin$=Get label of interval... 1 1 end$=Get label of interval... 1 p printline number of interval on tier 1: 'p' printline label of first interval on tier 1: 'begin$' printline label of last interval on tier 1: 'end$' m=(p-1)/2 printline 'label$' endproc procedure ReSegment_BE printline 'label$' select textgrid Remove select sound'i' sampling_frequency = Get sampling frequency duration = Get total duration #extract part... is a function available for Sound objects, in the Convert... menu. not to be confused with Index:Extract Part... in the praat help menu. mySilenceB = Create Sound from formula... silence 1 0 1 sampling_frequency 0 select sound'i' myEnd = Extract part... 0 duration rectangular 1 no mySilenceBE = Create Sound from formula... silence 1 0 1 sampling_frequency 0 select mySilenceB plus myEnd plus mySilenceBE myNewSound = Concatenate select sound'i' plus mySilenceB plus myEnd plus mySilenceBE Remove select myNewSound Rename... 'label$' Save as WAV file... 'output_directory$''label$'.wav #redo segmentation once select myNewSound intensity=To Intensity... 80 0 select intensity textgrid=To TextGrid (silences)... -25.0 0.3 0.1 "" 'label$' select intensity Remove printline this sound file fixed select textgrid p=Get number of intervals... 1 begin$=Get label of interval... 1 1 end$=Get label of interval... 1 p printline number of interval on tier 1:'p' printline label of first interval on tier 1: 'begin$' printline label of last interval on tier 1: 'end$' m=(p-1)/2 printline 'label$' endproc procedure ReSegment_E printline 'label$' select textgrid Remove select sound'i' sampling_frequency = Get sampling frequency duration = Get total duration #extract part... is a function available for Sound objects, in the Convert... menu. not to be confused with Index:Extract Part... in the praat help menu. select sound'i' myEnd = Extract part... 0 duration rectangular 1 no mySilenceBE = Create Sound from formula... silence 1 0 1 sampling_frequency 0 select myEnd plus mySilenceBE myNewSound = Concatenate select sound'i' plus myEnd plus mySilenceBE Remove select myNewSound Rename... 'label$' Save as WAV file... 'output_directory$''label$'.wav #redo segmentation once select myNewSound intensity=To Intensity... 80 0 select intensity textgrid=To TextGrid (silences)... -25.0 0.3 0.1 "" 'label$' select intensity Remove printline this sound file fixed select textgrid p=Get number of intervals... 1 begin$=Get label of interval... 1 1 end$=Get label of interval... 1 p printline number of interval on tier 1: 'p' printline label of first interval on tier 1: 'begin$' printline label of last interval on tier 1: 'end$' m=(p-1)/2 printline 'label$' endproc