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
8c4603c
master
1using System . Runtime . InteropServices ; 2 3namespace Whisper . Internal 4{ 5/// <summary>Function pointer to report model loading progress</summary> 6[ UnmanagedFunctionPointer ( CallingConvention . StdCall )] 7delegate int pfnLoadProgress ( double progress , IntPtr pv ); 8 9/// <summary>Function pointer to implement cooperative cancellation</summary> 10[ UnmanagedFunctionPointer ( CallingConvention . StdCall )] 11delegate int pfnCancel ( IntPtr pv ); 12 13/// <summary>Callback functions for loading models</summary> 14public struct sLoadModelCallbacks 15{ 16/// <summary>Function pointer to report model loading progress</summary> 17[ MarshalAs ( UnmanagedType . FunctionPtr )] 18pfnLoadProgress ? progress ; 19 20/// <summary>Function pointer to implement cooperative cancellation</summary> 21[ MarshalAs ( UnmanagedType . FunctionPtr )] 22pfnCancel ? cancel ; 23 24// Not needed in C#, delegates can capture things 25IntPtr pv ; 26 27/// <summary>Wrap idiomatic C# things into these low-level C callbacks</summary> 28internal sLoadModelCallbacks ( CancellationToken cancelToken , Action < double >? pfnProgress ) 29{ 30if ( cancelToken != CancellationToken . None ) 31{ 32cancel = delegate ( IntPtr pv ) 33{ 34if ( cancelToken . IsCancellationRequested ) 35return 1 ; // S_FALSE 36return 0 ; // S_OK 37}; 38} 39else 40cancel = null ; 41 42if ( null != pfnProgress ) 43{ 44progress = delegate ( double val , IntPtr pv ) 45{ 46try 47{ 48pfnProgress ( val ); 49return 0 ; // S_OK 50} 51catch ( Exception ex ) 52{ 53NativeLogger . captureException ( ex ); 54return ex . HResult ; 55} 56}; 57} 58else 59progress = null ; 60 61pv = IntPtr . Zero ; 62} 63} 64}