55#include " loggerSetup.h"
66#include " speech.h"
77
8+ #include < CLI/CLI.hpp>
89#include < spdlog/spdlog.h>
910#include < string>
1011#include < wx/string.h>
1112
12- MainFrame::MainFrame (const wxString& title) : wxFrame(nullptr , wxID_ANY, title) {
13+ MainFrame::MainFrame (const wxString& title, int cliVoiceIndex, int cliOutputDeviceIndex, bool cliIsHelpRequested)
14+ : wxFrame(nullptr , wxID_ANY, title) {
15+ m_cliVoiceIndex = cliVoiceIndex;
16+ m_cliOutputDeviceIndex = cliOutputDeviceIndex;
17+ m_cliIsHelpRequested = cliIsHelpRequested;
1318 m_panel = new wxPanel (this , wxID_ANY);
1419 auto * mainSizer = new wxBoxSizer (wxVERTICAL);
1520 auto * selectionsSizer = new wxBoxSizer (wxHORIZONTAL);
@@ -80,7 +85,7 @@ void MainFrame::populateVoicesList() {
8085 for (const auto & voiceName : voices) {
8186 m_voicesList->AppendString (wxString::FromUTF8 (voiceName));
8287 }
83- m_voicesList->SetSelection (0 );
88+ m_voicesList->SetSelection (m_cliVoiceIndex );
8489}
8590
8691void MainFrame::populateDevicesList () {
@@ -94,7 +99,7 @@ void MainFrame::populateDevicesList() {
9499 auto isDefaultStr = device.isDefault ? " [default]" : " " ;
95100 m_outputDevicesList->AppendString (wxString::FromUTF8 (std::format (" {} {}" , isDefaultStr, device.name )));
96101 }
97- m_outputDevicesList->SetSelection (0 );
102+ m_outputDevicesList->SetSelection (m_cliOutputDeviceIndex );
98103}
99104
100105void MainFrame::OnRateSliderChange (wxCommandEvent& event) {
@@ -151,13 +156,24 @@ void MainFrame::OnCharEvent(wxKeyEvent& event) {
151156}
152157
153158bool MyApp::OnInit () {
154- InitializeLogging (MyApp::argc, MyApp::argv);
155- if (!wxApp::OnInit ()) {
156- spdlog::critical (" Failed to initialize WX" );
157- return false ;
158- }
159- MainFrame* frame = new MainFrame (" SIM test" );
159+ CLI::App cliApp{" SIM - Speak Instead of Me speech utility" };
160+ auto argv = cliApp.ensure_utf8 (MyApp::argv);
161+ bool cliIsDebugEnabled = false ;
162+ cliApp.add_flag (" -D,--debug" , cliIsDebugEnabled, " Enable the debug logging for release builds" );
163+ int cliVoiceIndex = 0 ;
164+ cliApp.add_option (" -v,--voice" , cliVoiceIndex, " Specify SAPI voice index to be selected at program start" );
165+ int cliOutputDeviceIndex = 0 ;
166+ cliApp.add_option (" -d,--device" , cliOutputDeviceIndex,
167+ " Specify output device number to be selected at program start" );
168+ bool cliIsHelpRequested = false ;
169+ CLI11_PARSE (cliApp, MyApp::argc, argv);
170+ InitializeLogging (MyApp::argc, MyApp::argv, cliIsDebugEnabled);
171+ auto * frame = new MainFrame (" SIM test" , cliVoiceIndex, cliOutputDeviceIndex, cliIsHelpRequested);
160172 frame->Show (true );
161173 spdlog::debug (" Main window shown" );
162174 return true ;
163175}
176+
177+ void MyApp::OnInitCmdLine (wxCmdLineParser& parser) {
178+ // Left empty to bypass wxWidgets cli parsing
179+ }
0 commit comments