From 2e307814dd3936e392149f0aa781e938e0af2aa5 Mon Sep 17 00:00:00 2001 From: arnavmehta7 Date: Fri, 10 Feb 2023 14:48:51 +0530 Subject: [PATCH] added if clause for checking --- whisperx/alignment.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/whisperx/alignment.py b/whisperx/alignment.py index 7af24e1a..95d0b8a1 100644 --- a/whisperx/alignment.py +++ b/whisperx/alignment.py @@ -389,10 +389,11 @@ def align( wseg["segment-text-end"].fillna(len(text)-1, inplace=True) cseg = char_segments_arr.loc[seg_idx].loc[sub_start:sub_end-1] - cseg['segment-text-start'] = cseg['level_1'] - cseg['segment-text-end'] = cseg['level_1'] + 1 - del cseg['level_1'] - del cseg['level_0'] + # fixes bug for single segment in transcript + cseg['segment-text-start'] = cseg['level_1'] if 'level_1' in cseg else 0 + cseg['segment-text-end'] = cseg['level_1'] + 1 if 'level_1' in cseg else 1 + if 'level_1' in cseg: del cseg['level_1'] + if 'level_0' in cseg: del cseg['level_0'] cseg.reset_index(inplace=True) aligned_segments.append( {