Topics

mietta's pause script

timp@...
 

I have done a little modification to the pause finding
script in the files section so that it now works
with the new praat,
however, Get number of intervals, from the script
that breaks up the file into intervals does not seem to
work--
praat refuses to Get number of intervals now..
here is the pause script-- I'm going to fiddle
it some more to eventually detect intonational
phrases defined on acoustic criteria--
any suggestions as to the best way to this would be
appreciated(just beginning with scripting
in praat- sad as it is I was working in bloody
visual basic before)# This script creates a TextGrid object for a
LongSound object and sets boundaries at pauses
# on the basis of an intensity analysis.
# The boundaries will be set either in the centre time of a pause or
at the beginning and end of pauses.
# You may set the parameters for the pause analysis below -
# see the instructions after lines marked with !!!!!!!!!! (there are
four of these lines)
#
# How to run this script:
# 1. Open the Praat program
# 2. Before running the script, you should open a LongSound file
(Read menu)
# and make sure it is selected in the Object window.
# 3. Choose Open script from the Control menu
# 4. Look for this text file.
# 5. Select your LongSound object AND a corresponding TextGrid object
from the object list.
# 6. Then choose Run from the Run menu of the script window.
# 7. Afterwards, remember to save the TextGrid object that was
created.
#
#*********************************************************************
*********************************
# DEFAULT VALUES (initialization of variables)
# The name of the selected LongSound object is put to string
soundname$:
soundname$ = selected$ ("LongSound", 1)
select TextGrid 'soundname$'
Edit
editor TextGrid 'soundname$'
endeditor
endofsound = Get finishing time
select LongSound 'soundname$'
pausenumber = 0
duration = 0
count = 0
loops = 0
pauses_found = 0
windowstart = 0
windowend = 0
frame = 0
frames = 0
time = 0
intensity = 0
pausedetected = 0
pausestart = 0
pauseend = 0
pausenumber = 0
halfpause = 0

# This form prompts for parameters for the pause analysis:
form Give the parameters for pause analysis
comment This script marks the pauses in the LongSound to the
IntervalTier of the TextGrid.
comment Give the time period you wish to include (The TextGrid
will be overwritten!):
real Starting_time_(seconds) 0
real Finishing_time_(0=all) 120 (=3 minutes)
comment The following criteria define a pause:
positive Minimum_duration_(seconds) 0.5
positive Maximum_intensity_(dB) 55
comment Give the intensity analysis parameters:
positive Minimum_pitch_(Hz) 100
integer Time_step_(0=auto) 0
comment Give the window size for the intensity analyses (smaller
window requires less memory):
positive Window_size_(seconds) 30
endform

if finishing_time < 0
exit Finishing time must be greater than or equal to zero! (If you
give a zero, the whole LongSound will be analysed.)
endif
if finishing_time = 0
finishing_time = endofsound
endif

#*********************************************************************
*********************************
# BEGIN
#*********************************************************************
*********************************
# DIVIDE LONGSOUND INTO SHORTER PERIODS AND LOOP THROUGH EACH
duration = finishing_time - starting_time
#---------------------------------------------------------------------
-----------------------------
# Default number of loops is 1
loops = 1
# but if the period to be analysed is longer than 60 seconds, it will
be divided into 60-second
# periods for which the analysis is made:
if duration > window_size
loops = (duration/window_size)
endif
pause 'loops' Intensity windows, 'window_size' seconds each, will
have to be calculated. Are you sure?
#---------------------------------------------------------------------
-----------------------------
# START LOOPING THROUGH SHORT WINDOWS HERE
count = 1
while count <= loops
# Create a window of the LongSound and extract it for analysis
windowstart = starting_time + ((count - 1) * window_size)
windowend = starting_time + (count * window_size)
if windowend > endofsound
windowend = endofsound
endif
if windowend > finishing_time
windowend = finishing_time
endif
select LongSound 'soundname$'
Extract part... windowstart windowend yes
windowname$ = "Window_" + "'count'"
Rename... 'windowname$'
Edit
editor Sound 'windowname$'
endeditor
#-------------------------------------------------------------
-------------------------------------
# CALCULATE INTENSITY
To Intensity... minimum_pitch time_step
frames = Get number of frames
#-------------------------------------------------------------
-------------------------------------
# Check the pause criteria
pauseend = 0
frame = 1
#-----------------------------------------------------
---------------------------------------------
# Loop through all frames in the Intensity object:
while frame <= frames
select Intensity 'windowname$'
intensity = Get value in frame... frame
time = Get time from frame... frame
if intensity > maximum_intensity
# If the end of an earlier
detected possible pause has been reached:
if pausedetected = 1
if frame - 1 < 1
pauseend = windowstart
else
pauseend = Get time
from frame... (frame - 1)
endif
pausedetected = 0
endif
# If below intensity limit, a
possible new pause is started if one hasn't been detected yet:
elsif pausedetected = 0
pausestart = Get time
from frame... frame
pauseend = 0
pausedetected = 1
pausenumber =
pausenumber + 1
# If a detected pause just continues,
do nothing special.
endif
#---------------------------------------------
-----------------------------------------------------
# IF PAUSE CRITERIA ARE FULFILLED, ADD A
BOUNDARY OR TWO TO TEXTGRID
if pauseend > 0
pauseduration = pauseend - pausestart
if pauseduration >= minimum_duration
select Sound 'windowname$'
editor Sound 'windowname$'
#Move B to... pausestart
#Move E to... pauseend

Select... pausestart pauseend

Move begin of selection to nearest zero crossing

Move end of selection to nearest zero crossing

#this bit may stuff it

pausestart = Get begin of selection

pauseend = Get end of selection

Select... pausestart pauseend

#these tow moves may stuff it
endeditor
select TextGrid 'soundname$'
editor TextGrid 'soundname$'
#halfpause =
pauseduration / 2
#boundary =
pausestart
Move cursor to...
pausestart
Add on tier 1
Move cursor
to... pauseend
Add on tier 1

endeditor
pauseend = 0
pauses_found = pauses_found + 1
endif
endif
frame = frame + 1
# When all frames in the intensity analysis
have been looked at, end the frame loop.
endwhile
#-----------------------------------------------------
---------------------------------------------
select Sound 'windowname$'
Remove
select Intensity 'windowname$'
Remove
# END LOOPING THROUGH WINDOWS HERE
count = count + 1
endwhile
select LongSound 'soundname$'
plus TextGrid 'soundname$'
Edit
echo 'pauses_found' pauses were found and marked! (Remember to save
the TextGrid!)

#*********************************************************************
*********************************
#mods by tim to get zero crossings after amplitude decision to mark
pause/speech edges
#best params for max segmentation are 0 .04 for time step, intensity
set by the quietest bit of
#speech, and do it after cooledit pause removal with zero transition
width, zero smoothing, precision9
#fft size 4096 on pause then breaths (it would probably be good to
join together a sample
#both speakers's breaths to train the cooledit recogniser better
#check to see if intensity is fucked with in program (haven't done
this yet)