From 8c4603c73675958efc960fbd4bb599a2909d106a Mon Sep 17 00:00:00 2001 From: Konstantin Date: Mon, 16 Jan 2023 14:52:43 +0100 Subject: Source codes --- Examples/MicrophoneCS/MicrophoneCS.cs | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Examples/MicrophoneCS/MicrophoneCS.cs (limited to 'Examples/MicrophoneCS/MicrophoneCS.cs') diff --git a/Examples/MicrophoneCS/MicrophoneCS.cs b/Examples/MicrophoneCS/MicrophoneCS.cs new file mode 100644 index 0000000..c095ee1 --- /dev/null +++ b/Examples/MicrophoneCS/MicrophoneCS.cs @@ -0,0 +1,56 @@ +using Whisper; + +namespace MicrophoneCS +{ + static class Program + { + static int Main( string[] args ) + { + try + { + CommandLineArgs cla; + try + { + cla = new CommandLineArgs( args ); + } + catch( OperationCanceledException ) + { + return 1; + } + const eLoggerFlags loggerFlags = eLoggerFlags.UseStandardError | eLoggerFlags.SkipFormatMessage; + Library.setLogSink( eLogLevel.Debug, loggerFlags ); + + using iMediaFoundation mf = Library.initMediaFoundation(); + CaptureDeviceId[] devices = mf.listCaptureDevices() ?? + throw new ApplicationException( "This computer has no audio capture devices" ); + + if( cla.listDevices ) + { + for( int i = 0; i < devices.Length; i++ ) + Console.WriteLine( "#{0}: {1}", i, devices[ i ].displayName ); + return 0; + } + if( cla.captureDeviceIndex < 0 || cla.captureDeviceIndex >= devices.Length ) + throw new ApplicationException( $"Capture device index is out of range; the valid range is [ 0 .. {devices.Length - 1} ]" ); + + using iAudioCapture captureDev = mf.openCaptureDevice( devices[ cla.captureDeviceIndex ] ); + + using iModel model = Library.loadModel( cla.model ); + using Context context = model.createContext(); + cla.apply( ref context.parameters ); + + CaptureThread thread = new CaptureThread( cla, context, captureDev ); + thread.join(); + + context.timingsPrint(); + return 0; + } + catch( Exception ex ) + { + // Console.WriteLine( ex.Message ); + Console.WriteLine( ex.ToString() ); + return ex.HResult; + } + } + } +} \ No newline at end of file -- cgit v1.2.3