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
1#include "stdafx.h" 2#include "LanguageDropdown.h" 3#include "miscUtils.h" 4 5namespace 6{ 7inline wchar_t toUpper (wchar_t c ) 8 { 9size_t st = (uint16_t )c ; 10st = reinterpret_cast < size_t > (CharUpperW (reinterpret_cast < LPWSTR > (st ) ) ); 11return (wchar_t )(uint16_t )st ; 12 } 13 14void makeTitleCase (CString & s ) 15 { 16bool cap = true; 17for (int i = 0 ;i < s .GetLength ();i ++ ) 18 { 19wchar_t c = s [i ]; 20if (cap ) 21 { 22c = toUpper (c ); 23s .SetAt (i ,c ); 24 } 25cap = false; 26if (c == ' ' ) 27cap = true; 28 } 29 } 30} 31 32int LanguageDropdown ::getInitialSelection (AppState & state )const 33{ 34constexpr uint32_t english = 0x6E65 ; 35 36// Load preference from the registry 37uint32_t id = state .languageRead (); 38if (id == UINT_MAX ) 39id = english ; 40 41auto it = std::find (keys .begin (),keys .end (),id ); 42if (it == keys .end () ) 43 { 44id = english ; 45it = std::find (keys .begin (),keys .end (),id ); 46assert (it != keys .end () ); 47 } 48 49ptrdiff_t idx = it - keys .begin (); 50return (int )idx ; 51} 52 53void LanguageDropdown ::initialize (HWND owner ,int idc ,AppState & state ) 54{ 55m_hWnd = GetDlgItem (owner ,idc ); 56assert (nullptr != m_hWnd ); 57 58Whisper ::sLanguageList list ; 59Whisper ::getSupportedLanguages (list ); 60 61const size_t length = list .length ; 62keys .resize (length ); 63CString utf16 ; 64for (size_t i = 0 ;i < length ;i ++ ) 65 { 66keys [i ]= list .pointer [i ].key ; 67makeUtf16 (utf16 ,list .pointer [i ].name ); 68makeTitleCase (utf16 ); 69SendMessage (m_hWnd ,CB_ADDSTRING ,0 , (LPARAM )cstr (utf16 ) ); 70 } 71 72const int curSel = getInitialSelection (state ); 73SendMessage (m_hWnd ,CB_SETCURSEL ,curSel ,0 ); 74} 75 76uint32_t LanguageDropdown ::selectedLanguage () 77{ 78const int cs = (int )SendMessage (m_hWnd ,CB_GETCURSEL ,0 ,0 ); 79if (cs < 0 || cs >=keys .size () ) 80return UINT_MAX ; 81return keys [cs ]; 82} 83 84void LanguageDropdown ::saveSelection (AppState & state ) 85{ 86state .languageWrite (selectedLanguage () ); 87}