Skip to content

Commit

Permalink
Fixed a case where new segment was still triggered.
Browse files Browse the repository at this point in the history
  • Loading branch information
sandrohanea committed Apr 29, 2023
1 parent dfee1bc commit 79e553e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Whisper.net/WhisperProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ private bool OnEncoderBegin(IntPtr ctx, IntPtr state, IntPtr user_data)

private void OnNewSegment(IntPtr ctx, IntPtr state, int n_new, IntPtr user_data)
{
if (currentCancellationToken.HasValue && currentCancellationToken.Value.IsCancellationRequested)
{
return;
}

var segments = NativeMethods.whisper_full_n_segments_from_state(state);

while (segmentIndex < segments)
Expand Down Expand Up @@ -518,6 +523,10 @@ private void OnNewSegment(IntPtr ctx, IntPtr state, int n_new, IntPtr user_data)
foreach (var handler in options.OnSegmentEventHandlers)
{
handler?.Invoke(eventHandlerArgs);
if (currentCancellationToken.HasValue && currentCancellationToken.Value.IsCancellationRequested)
{
return;
}
}
}

Expand Down

0 comments on commit 79e553e

Please sign in to comment.