clearinfo
quote$ = "'"
path$ = "C:\WINDOWS\Bureau\cours_slow5"
sound = selected("Sound")
textgrid = selected("TextGrid")


select 'sound'
To Pitch... 0.01 75 600
pitch = selected("Pitch")
select 'textgrid'
outputfile1$ = path$ + "\resultats\" + "resultats.xls"

fileappend "'outputfile1$'" 'tab$' "sound". 'newline$''tab$'Duration'tab$'Fo mean''tab$'Fo mid'newline$'

select 'textgrid'


call  comptage1
call calculs



#----------------------------------
procedure comptage1

noiist = Get number of intervals... 1
nos = 0
for j from 1 to noiist

syllable$ = Get label of interval... 1 j
if (syllable$ <> "_" and syllable$ <> "_ " and syllable$ <> "1"and syllable$ <> " " and syllable$ <> "")

nos = nos + 1
syllable'nos' = j
endif
endfor

endproc

#-----------------------------------
#---------------------------------
procedure calculs
	
for l from 1 to nos
select 'textgrid'
current_syllable = syllable'l'
label$ = Get label of interval... 1 current_syllable
				
start_syllable = Get starting point... 1 current_syllable
end_syllable = Get end point... 1 current_syllable
syllable_duration = round((end_syllable - start_syllable)*1000)
midpt = (start_syllable + end_syllable)/2		
							
fileappend "'outputfile1$'" ('label$') 'tab$' 'syllable_duration'

select 'pitch'	
		 						
mean_Fo = Get mean... 'start_syllable' 'end_syllable' Hertz
mean_Fo = round (mean_Fo)	

mid_Fo = Get value at time... midpt Hertz Linear
mid_Fo = round (mid_Fo)	


fileappend "'outputfile1$'"  'tab$' 'mean_Fo' 'tab$' 'mid_Fo' 'newline$'

endfor
endproc


