yum-archive/TaSTT-Whisper

High-performance GPGPU inference of OpenAI's Whisper automatic speech recognition (ASR) model

git clone https://git.yummers.dev/yum-archive/TaSTT-Whisper

KonstantinConsistent cancellation API across the library: S_OK = continue, S_FALSE = stopad097a7

master
1.1 KiB49 linesraw
1using Whisper.Internal;
2
3namespace Whisper
4{
5	/// <summary>Implement this abstract class to provide callbacks for audio capture method</summary>
6	public abstract class CaptureCallbacks
7	{
8		/// <summary>Override this method to support cancellation</summary>
9		protected virtual bool shouldCancel( Context sender ) { return false; }
10
11		/// <summary>Override this method to get notified about status changes</summary>
12		protected virtual void captureStatusChanged( Context sender, eCaptureStatus status ) { }
13
14		internal pfnShouldCancel cancel( Context sender )
15		{
16			const int S_OK = 0;
17			const int S_FALSE = 1;
18			return delegate ( IntPtr pv )
19			{
20				try
21				{
22					return shouldCancel( sender ) ? S_FALSE : S_OK;
23				}
24				catch( Exception ex )
25				{
26					NativeLogger.captureException( ex );
27					return ex.HResult;
28				}
29			};
30		}
31
32		internal pfnCaptureStatus status( Context sender )
33		{
34			return delegate ( IntPtr pv, eCaptureStatus status )
35			{
36				try
37				{
38					captureStatusChanged( sender, status );
39					return 0;
40				}
41				catch( Exception ex )
42				{
43					NativeLogger.captureException( ex );
44					return ex.HResult;
45				}
46			};
47		}
48	}
49}