Skip to content

Commit

Permalink
Fix window right boundary time larger than audio file max time
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Keshet committed Aug 26, 2014
1 parent dd17a37 commit f80e8b0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions autovot/bin/auto_vot_extract_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ def textgrid2front_end(textgrid_list, wav_list, input_filename, features_filenam
logging.error('(sox can be downloaded from http://sox.sourceforge.net)')
problematic_files.append(wav_filename)
continue
num_samples = wav_file.getnframes()
wav_duration = num_samples/float(wav_file.getframerate())
print "wav_duration=", wav_duration
textgrid = TextGrid()

# read TextGrid
Expand All @@ -161,15 +164,16 @@ def textgrid2front_end(textgrid_list, wav_list, input_filename, features_filenam
logging.error("Either --window_tier or --vot_tier should be given.")
exit(-1)

# check if the VOT tier is one of the tiers in the TextGrid
# check if the VOT tier is one of the tiers in the TextGrid
if definitions.vot_tier in tier_names:
tier_index = tier_names.index(definitions.vot_tier)
# run over all intervals in the tier
for interval in textgrid[tier_index]:
if (definitions.vot_mark == "*" and re.search(r'\S', interval.mark())) \
or (interval.mark() == definitions.vot_mark):
window_min = max(interval.xmin() + definitions.window_min, 0)
window_max = min(interval.xmax() + definitions.window_max, textgrid.xmax())
window_max = min(min(interval.xmax() + definitions.window_max, textgrid.xmax()), wav_duration)
print window_max
new_instance = Instance()
new_instance.set(wav_filename, window_min, window_max, interval.xmin(), interval.xmax())
instances.append(new_instance)
Expand Down
2 changes: 1 addition & 1 deletion autovot/bin/helpers/textgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def read(self, file):
text.readline()
for i in range(m): # loop over grids
text.readline()
if text.readline().rstrip().split()[2] == '"IntervalTier"':
if text.readline().rstrip().split()[2] == '"IntervalTier"':
# inam = text.readline().rstrip().split()[2][1:-1]
inam = text.readline().split('=')[1].strip().strip('"') # Joseph Keshet: handle space in the tier name
imin = float(text.readline().rstrip().split()[2])
Expand Down
4 changes: 3 additions & 1 deletion autovot/code/vot_predictor/VotFrontEnd2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ int main(int argc, char **argv)
instances.word_end[i] = (samples.size()-1)/double(sampling_rate);
}

if (instances.word_end[i] >= samples.size()/double(sampling_rate)) {
// round the wav file duration up to 3 figures after the point
double wav_duration = round(1000*samples.size()/double(sampling_rate))/1000.0;
if (instances.word_end[i] > wav_duration) {
LOG(ERROR) << "Word end (" << instances.word_end[i] << ") is greater than "
<< "the length of " << instances.file_list[i];
return EXIT_FAILURE;
Expand Down

0 comments on commit f80e8b0

Please sign in to comment.