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

KonstantinC# microphone example, diarize integration1be5537

master
1.6 KiB59 linesraw
1using Whisper;
2
3namespace MicrophoneCS
4{
5	static class Program
6	{
7		static int Main( string[] args )
8		{
9			try
10			{
11				CommandLineArgs cla;
12				try
13				{
14					cla = new CommandLineArgs( args );
15				}
16				catch( OperationCanceledException )
17				{
18					return 1;
19				}
20				const eLoggerFlags loggerFlags = eLoggerFlags.UseStandardError | eLoggerFlags.SkipFormatMessage;
21				Library.setLogSink( eLogLevel.Debug, loggerFlags );
22
23				using iMediaFoundation mf = Library.initMediaFoundation();
24				CaptureDeviceId[] devices = mf.listCaptureDevices() ??
25					throw new ApplicationException( "This computer has no audio capture devices" );
26
27				if( cla.listDevices )
28				{
29					for( int i = 0; i < devices.Length; i++ )
30						Console.WriteLine( "#{0}: {1}", i, devices[ i ].displayName );
31					return 0;
32				}
33				if( cla.captureDeviceIndex < 0 || cla.captureDeviceIndex >= devices.Length )
34					throw new ApplicationException( $"Capture device index is out of range; the valid range is [ 0 .. {devices.Length - 1} ]" );
35
36				sCaptureParams cp = new sCaptureParams();
37				if( cla.diarize )
38					cp.flags |= eCaptureFlags.Stereo;
39				using iAudioCapture captureDev = mf.openCaptureDevice( devices[ cla.captureDeviceIndex ], cp );
40
41				using iModel model = Library.loadModel( cla.model );
42				using Context context = model.createContext();
43				cla.apply( ref context.parameters );
44
45				CaptureThread thread = new CaptureThread( cla, context, captureDev );
46				thread.join();
47
48				context.timingsPrint();
49				return 0;
50			}
51			catch( Exception ex )
52			{
53				// Console.WriteLine( ex.Message );
54				Console.WriteLine( ex.ToString() );
55				return ex.HResult;
56			}
57		}
58	}
59}