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
509c0ca
master
1#pragma once 2#include "AppState.h" 3#include "Utils/WTL/atlddx.h" 4#include "Utils/WTL/atlcrack.h" 5#include "Utils/miscUtils.h" 6#include "Utils/LanguageDropdown.h" 7#include "Utils/TranslateCheckbox.h" 8#include "Utils/PendingState.h" 9 10class TranscribeDlg : 11public CDialogImpl < TranscribeDlg > , 12public CWinDataExchange < TranscribeDlg > , 13public iThreadPoolCallback 14{ 15AppState & appState ; 16 17public : 18static constexpr UINT IDD = IDD_TRANSCRIBE_DIALOG ; 19static constexpr UINT WM_CALLBACK_STATUS = WM_APP + 1 ; 20 21TranscribeDlg ( AppState & app ) : appState ( app ) { } 22 23// Show this dialog modally, without parent. 24HRESULT show (); 25 26BEGIN_MSG_MAP ( LoadModelDlg ) 27MESSAGE_HANDLER ( WM_INITDIALOG , OnInitDialog ) 28ON_BUTTON_CLICK ( IDC_CONSOLE , cbConsole . click ) 29ON_BUTTON_CLICK ( IDCANCEL , onClose ) 30ON_BUTTON_CLICK ( IDC_BACK , onBack ) 31ON_BUTTON_CLICK ( IDC_USE_INPUT_FOLDER , onInputFolderCheck ) 32ON_BUTTON_CLICK ( IDC_BROWSE_MEDIA , onBrowseMedia ) 33ON_BUTTON_CLICK ( IDC_BROWSE_RESULT , onBrowseOutput ) 34ON_BUTTON_CLICK ( IDC_TRANSCRIBE , onTranscribe ) 35ON_BUTTON_CLICK ( IDC_CAPTURE , onCapture ) 36COMMAND_HANDLER ( IDC_OUTPUT_FORMAT , CBN_SELCHANGE , onOutFormatChange ) 37COMMAND_HANDLER ( IDC_PATH_MEDIA , EN_CHANGE , onInputChange ) 38MESSAGE_HANDLER ( WM_CALLBACK_STATUS , onCallbackStatus ) 39MSG_WM_CLOSE ( onWmClose ) 40END_MSG_MAP () 41 42BEGIN_DDX_MAP ( LoadModelDlg ) 43DDX_CONTROL_HANDLE ( IDC_MODEL_DESC , modelDesc ) 44DDX_CONTROL_HANDLE ( IDC_PATH_MEDIA , sourceMediaPath ) 45DDX_CONTROL_HANDLE ( IDC_OUTPUT_FORMAT , transcribeOutFormat ) 46DDX_CONTROL_HANDLE ( IDC_USE_INPUT_FOLDER , useInputFolder ) 47DDX_CONTROL_HANDLE ( IDC_PATH_RESULT , transcribeOutputPath ) 48DDX_CONTROL_HANDLE ( IDC_BROWSE_RESULT , transcribeOutputBrowse ); 49DDX_CONTROL_HANDLE ( IDC_TRANSCRIBE_PROGRESS , progressBar ); 50END_DDX_MAP () 51 52private : 53PendingState pendingState ; 54void setPending ( bool nowPending ); 55void transcribeError ( LPCTSTR text , HRESULT hr = S_FALSE ); 56 57LRESULT OnInitDialog ( UINT nMessage , WPARAM wParam , LPARAM lParam , BOOL & bHandled ); 58 59void onClose () 60{ 61ATLVERIFY ( EndDialog ( IDCANCEL ) ); 62} 63void onBack () 64{ 65ATLVERIFY ( EndDialog ( IDC_BACK ) ); 66} 67 68void printModelDescription (); 69CStatic modelDesc ; 70ConsoleCheckbox cbConsole ; 71 72LanguageDropdown languageSelector ; 73TranslateCheckbox cbTranslate ; 74 75CEdit sourceMediaPath ; 76CButton useInputFolder ; 77CEdit transcribeOutputPath ; 78CButton transcribeOutputBrowse ; 79CComboBox transcribeOutFormat ; 80CProgressBarCtrl progressBar ; 81void populateOutputFormats (); 82 83LRESULT onOutFormatChange ( UINT , INT , HWND , BOOL & bHandled ); 84LRESULT onInputChange ( UINT , INT , HWND , BOOL & ); 85void onInputFolderCheck (); 86void onBrowseMedia (); 87void onBrowseOutput (); 88void onTranscribe (); 89void onCapture () 90{ 91EndDialog ( IDC_CAPTURE ); 92} 93 94ThreadPoolWork work ; 95 96enum struct eOutputFormat : uint8_t ; 97 98struct TranscribeArgs 99{ 100CString pathMedia ; 101CString pathOutput ; 102uint32_t language ; 103bool translate ; 104eOutputFormat format ; 105Whisper :: eResultFlags resultFlags ; 106uint64_t startTime ; 107int64_t mediaDuration ; 108CString errorMessage ; 109}; 110TranscribeArgs transcribeArgs ; 111 112void __stdcall poolCallback () noexcept override final ; 113 114LRESULT onCallbackStatus ( UINT , WPARAM wParam , LPARAM , BOOL & bHandled ); 115 116HRESULT transcribe (); 117void getThreadError (); 118119 static HRESULT writeTextFile ( const Whisper :: sSegment * const segments , const size_t length , CAtlFile & file , bool timestamps ); 120static HRESULT writeSubRip ( const Whisper :: sSegment * const segments , const size_t length , CAtlFile & file ); 121static HRESULT writeWebVTT ( const Whisper :: sSegment * const segments , const size_t length , CAtlFile & file ); 122 123static HRESULT __cdecl newSegmentCallbackStatic ( Whisper :: iContext * ctx , uint32_t n_new , void * user_data ) noexcept ; 124HRESULT newSegmentCallback ( Whisper :: iContext * ctx , uint32_t n_new ); 125 126static HRESULT __cdecl progressCallbackStatic ( double p , Whisper :: iContext * ctx , void * pv ) noexcept ; 127HRESULT progressCallback ( double p ) noexcept ; 128 129void onWmClose (); 130// Populate output path based on the provided input media path 131void setOutputPath ( const CString & input ); 132// Populate output path based on the input media path in the edit box 133void setOutputPath (); 134};