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 . ExceptionServices ; 2using Whisper ; 3 4namespace MicrophoneCS 5{ 6sealed class CaptureThread : CaptureCallbacks 7{ 8public CaptureThread ( CommandLineArgs args , Context context , iAudioCapture source ) 9{ 10callbacks = new TranscribeCallbacks ( args ); 11this . context = context ; 12this . source = source ; 13 14thread = new Thread ( threadMain ) { Name = "Capture Thread" }; 15Console . WriteLine ( "Press any key to quit" ); 16thread . Start (); 17} 18 19static void readKeyCallback ( object ? state ) 20{ 21CaptureThread ct = ( state as CaptureThread ) ?? throw new ApplicationException (); 22Console . ReadKey (); 23ct . shouldQuit = true ; 24} 25 26public void join () 27{ 28ThreadPool . QueueUserWorkItem ( readKeyCallback , this ); 29thread . Join (); 30edi ? . Throw (); 31} 32 33volatile bool shouldQuit = false ; 34 35protected override bool shouldCancel ( Context sender ) => 36shouldQuit ; 37 38protected override void captureStatusChanged ( Context sender , eCaptureStatus status ) 39{ 40Console . WriteLine ( $"CaptureStatusChanged: { status } " ); 41} 42 43readonly TranscribeCallbacks callbacks ; 44readonly Thread thread ; 45readonly Context context ; 46readonly iAudioCapture source ; 47ExceptionDispatchInfo ? edi = null ; 48 49void threadMain () 50{ 51try 52{ 53context . runCapture ( source , callbacks , this ); 54} 55catch ( Exception ex ) 56{ 57edi = ExceptionDispatchInfo . Capture ( ex ); 58} 59} 60} 61}