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 3/// <summary>Utility class to setup console coloring with ANSI codes.</summary> 4/// <remarks>The feature requires Windows 10 or newer</remarks> 5static class AnsiCodes 6{ 7const string dll = "kernel32.dll" ; 8 9[ DllImport ( dll , SetLastError = true )] 10static extern IntPtr GetStdHandle ( int nStdHandle ); 11 12const int STD_OUTPUT_HANDLE = - 11 ; 13 14[ Flags ] 15enum ConsoleModes : uint 16{ 17// Input flags 18ENABLE_PROCESSED_INPUT = 0x0001 , 19ENABLE_LINE_INPUT = 0x0002 , 20ENABLE_ECHO_INPUT = 0x0004 , 21ENABLE_WINDOW_INPUT = 0x0008 , 22ENABLE_MOUSE_INPUT = 0x0010 , 23ENABLE_INSERT_MODE = 0x0020 , 24ENABLE_QUICK_EDIT_MODE = 0x0040 , 25ENABLE_EXTENDED_FLAGS = 0x0080 , 26ENABLE_AUTO_POSITION = 0x0100 , 27ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200 , 28 29// Output flags 30ENABLE_PROCESSED_OUTPUT = 0x0001 , 31ENABLE_WRAP_AT_EOL_OUTPUT = 0x0002 , 32ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004 , 33DISABLE_NEWLINE_AUTO_RETURN = 0x0008 , 34ENABLE_LVB_GRID_WORLDWIDE = 0x0010 35} 36 37[ DllImport ( dll , SetLastError = true )] 38static extern bool GetConsoleMode ( IntPtr hConsoleHandle , out ConsoleModes mode ); 39 40[ DllImport ( dll , SetLastError = true )] 41static extern bool SetConsoleMode ( IntPtr hConsoleHandle , ConsoleModes mode ); 42 43static AnsiCodes () 44{ 45IntPtr h = GetStdHandle ( STD_OUTPUT_HANDLE ); 46IntPtr INVALID_HANDLE_VALUE = ( IntPtr )( - 1 ); 47if ( h == INVALID_HANDLE_VALUE ) 48return ; 49 50if ( ! GetConsoleMode ( h , out ConsoleModes mode ) ) 51return ; 52 53if ( mode . HasFlag ( ConsoleModes . ENABLE_VIRTUAL_TERMINAL_PROCESSING ) ) 54{ 55enabled = true ; 56return ; 57} 58 59mode |= ConsoleModes . ENABLE_VIRTUAL_TERMINAL_PROCESSING ; 60if ( SetConsoleMode ( h , mode ) ) 61{ 62enabled = true ; 63return ; 64} 65} 66 67public static readonly bool enabled = false ; 68}