diff options
| author | yum <yum.food.vr@gmail.com> | 2023-02-24 12:52:48 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2023-02-24 12:52:48 -0800 |
| commit | c1c8d552d2d6643aa34f3fde8816c3a9101ac157 (patch) | |
| tree | 1b5605c6c77e64d1d034ac94252146cbbe27cfe1 | |
| parent | fa1f619fcaaf7d40670d11f492cd0156a85bcf03 (diff) | |
Add hack to prevent browser source crash on shutdown
Documented in BrowserSource::Run().
* Parameterize Release/Debug in build scripts
| -rw-r--r-- | GUI/GUI/GUI/BrowserSource.cpp | 48 | ||||
| -rw-r--r-- | GUI/GUI/GUI/BrowserSource.h | 32 | ||||
| -rw-r--r-- | GUI/GUI/GUI/Frame.cpp | 27 | ||||
| -rw-r--r-- | GUI/GUI/GUI/GUI.vcxproj | 7 | ||||
| -rw-r--r-- | GUI/GUI/GUI/GUI.vcxproj.filters | 6 | ||||
| -rw-r--r-- | GUI/GUI/GUI/GUI.vcxproj.user | 11 | ||||
| -rw-r--r-- | GUI/GUI/GUI/WhisperCPP.cpp | 26 | ||||
| -rw-r--r-- | GUI/Libraries/fetch.ps1 | 12 | ||||
| -rw-r--r-- | GUI/package.ps1 | 8 |
9 files changed, 109 insertions, 68 deletions
diff --git a/GUI/GUI/GUI/BrowserSource.cpp b/GUI/GUI/GUI/BrowserSource.cpp index 0b4ad31..9bf19cb 100644 --- a/GUI/GUI/GUI/BrowserSource.cpp +++ b/GUI/GUI/GUI/BrowserSource.cpp @@ -12,22 +12,40 @@ BrowserSource::BrowserSource(uint16_t port, wxTextCtrl *out) void BrowserSource::Run(volatile bool* run)
{
- oatpp::base::Environment::init();
- ScopeGuard oatpp_env_cleanup([]() { oatpp::base::Environment::destroy(); });
-
- AppComponent components(port_);
-
- OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);
- router->addController(std::make_shared<AppController>());
-
- OATPP_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>, connectionHandler);
-
- OATPP_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, connectionProvider);
-
- oatpp::network::Server server(connectionProvider, connectionHandler);
-
+ // TODO(yum) oatpp::base::Environment::destroy() accesses invalid memory if
+ // it's called after serving a connection. Probably a bug in my code. Fix it
+ // and then use a pattern like
+ // init();
+ // ScopeGuard cleanup([]() { destroy(); });
+ static bool did_init = false;
+ if (!did_init) {
+ oatpp::base::Environment::init();
+ }
+ //ScopeGuard oatpp_env_cleanup([]() { oatpp::base::Environment::destroy(); });
+
+ OATPP_CREATE_COMPONENT(
+ std::shared_ptr<oatpp::network::ServerConnectionProvider>,
+ serverConnectionProvider)([&] {
+ return oatpp::network::tcp::server::ConnectionProvider::createShared(
+ { "0.0.0.0", port_, oatpp::network::Address::IP_4 });
+ }());
+
+ OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, apiObjectMapper)([] {
+ return oatpp::parser::json::mapping::ObjectMapper::createShared();
+ }());
+
+ OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, httpRouter)([] {
+ return oatpp::web::server::HttpRouter::createShared();
+ }());
+ httpRouter.getObject()->addController(std::make_shared<AppController>(apiObjectMapper.getObject()));
+
+ OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>, serverConnectionHandler)([&] {
+ return oatpp::web::server::HttpConnectionHandler::createShared(httpRouter.getObject());
+ }());
+
+ oatpp::network::Server server(serverConnectionProvider.getObject(), serverConnectionHandler.getObject());
Log(out_, "Server running on port {}\n",
- static_cast<const char*>(connectionProvider->getProperty("port").getData()));
+ static_cast<const char*>(serverConnectionProvider.getObject()->getProperty("port").getData()));
server.run(std::function<bool()>([run]() { return *run == true; }));
}
diff --git a/GUI/GUI/GUI/BrowserSource.h b/GUI/GUI/GUI/BrowserSource.h index 37d45a7..0334088 100644 --- a/GUI/GUI/GUI/BrowserSource.h +++ b/GUI/GUI/GUI/BrowserSource.h @@ -34,7 +34,7 @@ class AppDto : public oatpp::DTO class AppController : public oatpp::web::server::api::ApiController
{
public:
- AppController(OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
+ AppController(std::shared_ptr<ObjectMapper> objectMapper)
: oatpp::web::server::api::ApiController(objectMapper)
{}
public:
@@ -49,36 +49,6 @@ public: #include OATPP_CODEGEN_END(ApiController)
-class AppComponent
-{
-public:
- AppComponent(uint16_t port) : port_(port) {}
-
- // TODO(yum) make port configurable. oatpp examples show how to use a port
- // that's available at boot time. Plumbing this with port_ or port causes
- // oatpp to use a different port every time, which I think is caused by port_
- // being uninitialized.
- OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, serverConnectionProvider)([] {
- return oatpp::network::tcp::server::ConnectionProvider::createShared({ "0.0.0.0", 9517, oatpp::network::Address::IP_4 });
- }());
-
- OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, httpRouter)([] {
- return oatpp::web::server::HttpRouter::createShared();
- }());
-
- OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>, serverConnectionHandler)([] {
- OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router); // get Router component
- return oatpp::web::server::HttpConnectionHandler::createShared(router);
- }());
-
- OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, apiObjectMapper)([] {
- return oatpp::parser::json::mapping::ObjectMapper::createShared();
- }());
-
-private:
- const uint16_t port_;
-};
-
class BrowserSource
{
public:
diff --git a/GUI/GUI/GUI/Frame.cpp b/GUI/GUI/GUI/Frame.cpp index ec7de2e..e67240a 100644 --- a/GUI/GUI/GUI/Frame.cpp +++ b/GUI/GUI/GUI/Frame.cpp @@ -952,12 +952,10 @@ Frame::Frame() "but are far more accurate.");
whisper_window_duration_ = whisper_window_duration;
- // TODO(yum) make this mutable once we figure out how to
- // get oatpp to accept a runtime src port.
auto* whisper_browser_src_port = new wxTextCtrl(
whisper_config_panel_pairs, ID_WHISPER_BROWSER_SRC_PORT,
std::to_string(app_c_.browser_src_port), wxDefaultPosition,
- wxDefaultSize, wxTE_READONLY);
+ wxDefaultSize, /*style=*/0);
whisper_browser_src_port->SetToolTip(
"This is the port that the browser source is hosted "
"on. If you aren't using TaSTT to stream, you can "
@@ -1340,15 +1338,16 @@ void Frame::ApplyConfigToInputFields() void Frame::PopulateDynamicInputFields()
{
- whisper_->Init();
- std::vector<std::string> mics;
- if (whisper_->GetMics(mics)) {
- std::vector<wxString> contents(mics.size());
- auto* whisper_mic = static_cast<wxChoice*>(FindWindowById(ID_WHISPER_MIC));
- for (int i = 0; i < std::min(mics.size(), kNumWhisperMicChoices); i++) {
- contents[i] = mics[i];
+ if (whisper_->Init()) {
+ std::vector<std::string> mics;
+ if (whisper_->GetMics(mics)) {
+ std::vector<wxString> contents(mics.size());
+ auto* whisper_mic = static_cast<wxChoice*>(FindWindowById(ID_WHISPER_MIC));
+ for (int i = 0; i < std::min(mics.size(), kNumWhisperMicChoices); i++) {
+ contents[i] = mics[i];
+ }
+ whisper_mic->Set(contents);
}
- whisper_mic->Set(contents);
}
}
@@ -1362,6 +1361,7 @@ void Frame::OnNavbarTranscribe(wxCommandEvent& event) {
// Initialize input fields using AppConfig.
ApplyConfigToInputFields();
+ PopulateDynamicInputFields();
transcribe_panel_->Hide();
unity_panel_->Hide();
@@ -1377,6 +1377,7 @@ void Frame::OnNavbarUnity(wxCommandEvent& event) {
// Initialize input fields using AppConfig.
ApplyConfigToInputFields();
+ PopulateDynamicInputFields();
transcribe_panel_->Hide();
unity_panel_->Hide();
@@ -1392,6 +1393,7 @@ void Frame::OnNavbarDebug(wxCommandEvent& event) {
// Initialize input fields using AppConfig.
ApplyConfigToInputFields();
+ PopulateDynamicInputFields();
transcribe_panel_->Hide();
unity_panel_->Hide();
@@ -1407,6 +1409,7 @@ void Frame::OnNavbarWhisper(wxCommandEvent& event) {
// Initialize input fields using AppConfig.
ApplyConfigToInputFields();
+ PopulateDynamicInputFields();
transcribe_panel_->Hide();
unity_panel_->Hide();
@@ -1416,8 +1419,6 @@ void Frame::OnNavbarWhisper(wxCommandEvent& event) whisper_panel_->Show();
- whisper_->Init();
-
Resize();
}
diff --git a/GUI/GUI/GUI/GUI.vcxproj b/GUI/GUI/GUI/GUI.vcxproj index 8db7fbf..e3fac34 100644 --- a/GUI/GUI/GUI/GUI.vcxproj +++ b/GUI/GUI/GUI/GUI.vcxproj @@ -78,6 +78,10 @@ <LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(ProjectDir)/whisper;$(ProjectDir)/oatpp</LibraryPath>
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);$(ProjectDir)</IncludePath>
</PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(ProjectDir)/whisper;$(ProjectDir)/oatpp</LibraryPath>
+ <IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);$(ProjectDir)</IncludePath>
+ </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
@@ -118,11 +122,12 @@ <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
- <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
+ <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;comdlg32.lib;winspool.lib;shell32.lib;shlwapi.lib;ole32.lib;oleaut32.lib;uuid.lib;advapi32.lib;version.lib;comctl32.lib;rpcrt4.lib;ws2_32.lib;wininet.lib;winmm.lib;Whisper.lib;oatpp.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
diff --git a/GUI/GUI/GUI/GUI.vcxproj.filters b/GUI/GUI/GUI/GUI.vcxproj.filters index 1ec73d1..2d87bd3 100644 --- a/GUI/GUI/GUI/GUI.vcxproj.filters +++ b/GUI/GUI/GUI/GUI.vcxproj.filters @@ -36,6 +36,9 @@ <ClCompile Include="WhisperCPP.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="BrowserSource.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="PythonWrapper.h">
@@ -68,6 +71,9 @@ <ClInclude Include="WhisperCPP.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="BrowserSource.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="GUI.rc">
diff --git a/GUI/GUI/GUI/GUI.vcxproj.user b/GUI/GUI/GUI/GUI.vcxproj.user index 0f14913..052eb16 100644 --- a/GUI/GUI/GUI/GUI.vcxproj.user +++ b/GUI/GUI/GUI/GUI.vcxproj.user @@ -1,4 +1,13 @@ <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <LocalDebuggerCommand>TaSTT.exe</LocalDebuggerCommand>
+ <LocalDebuggerWorkingDirectory>$(ProjectDir)/../../TaSTT/</LocalDebuggerWorkingDirectory>
+ <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <LocalDebuggerCommand>TaSTT.exe</LocalDebuggerCommand>
+ <LocalDebuggerWorkingDirectory>$(ProjectDir)/../../TaSTT/</LocalDebuggerWorkingDirectory>
+ <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
+ </PropertyGroup>
</Project>
\ No newline at end of file diff --git a/GUI/GUI/GUI/WhisperCPP.cpp b/GUI/GUI/GUI/WhisperCPP.cpp index b610941..c532123 100644 --- a/GUI/GUI/GUI/WhisperCPP.cpp +++ b/GUI/GUI/GUI/WhisperCPP.cpp @@ -27,8 +27,11 @@ using ::Logging::Log; namespace {
std::string wcharToAsciiString(const wchar_t* wc_str) {
int len = wcslen(wc_str);
- std::string result(len, 0);
+ if (len == 0) {
+ return "";
+ }
+ std::string result(len, 0);
size_t len_out;
wcstombs_s(&len_out, result.data(), len, wc_str, _TRUNCATE);
@@ -234,6 +237,8 @@ bool WhisperCPP::CreateContext(Whisper::iModel* model, Whisper::iContext*& conte }
void WhisperCPP::Start(const AppConfig& c) {
+ Init();
+
if (!transcription_thd_.valid()) {
Log(out_, "Transcription engine already running\n");
return;
@@ -312,6 +317,11 @@ void WhisperCPP::Start(const AppConfig& c) { return S_OK;
}
+ static const std::vector<std::string> banned_words{
+ " [BLANK_AUDIO]",
+ " [SOUND]",
+ };
+
const sSegment* const segments = results->getSegments();
const sToken* const tokens = results->getTokens();
const int s0 = length.countSegments - n_new;
@@ -322,6 +332,19 @@ void WhisperCPP::Start(const AppConfig& c) { const sToken& tok = tokens[seg.firstToken + j];
std::string_view tok_str(tok.text);
if (tok_str.starts_with("[") ||
+ tok_str.starts_with(" [")) {
+ if (tok_str.ends_with("]")) {
+ continue;
+ }
+ }
+ std::vector<std::string>::const_iterator word_iter =
+ std::find(banned_words.cbegin(), banned_words.cend(),
+ tok_str);
+ if (word_iter != banned_words.end()) {
+ continue;
+ }
+#if 0
+ if (tok_str.starts_with("[") ||
tok_str.starts_with(" [") ||
tok_str.starts_with(" (")) {
if (tok_str.ends_with("]") ||
@@ -341,6 +364,7 @@ void WhisperCPP::Start(const AppConfig& c) { if (tok_str.ends_with("BLANK_AUDIO")) {
continue;
}
+#endif
Log(out, "{}", tok.text);
}
}
diff --git a/GUI/Libraries/fetch.ps1 b/GUI/Libraries/fetch.ps1 index 550dfa5..1495cc9 100644 --- a/GUI/Libraries/fetch.ps1 +++ b/GUI/Libraries/fetch.ps1 @@ -1,7 +1,11 @@ param( - [switch]$overwrite = $false + [switch]$overwrite = $False, + [string]$release = "Release" ) +echo "Overwrite: $overwrite" +echo "Release: $release" + Set-PSDebug -trace 0 $WX_3_2_1_URL = "https://github.com/wxWidgets/wxWidgets/releases/download/v3.2.1/wxWidgets-3.2.1.zip" @@ -87,12 +91,12 @@ if (-Not (Test-Path oatpp)) { mkdir build pushd build > $null cmake.exe .. ` - -DCMAKE_BUILD_TYPE=Release ` + -DCMAKE_BUILD_TYPE=$release ` -DBUILD_SHARED_LIBS=OFF ` -DOATPP_MSVC_LINK_STATIC_RUNTIME=ON ` -DOATPP_BUILD_TESTS=OFF - cmake.exe --build . -j $NPROC --config Release - cp src/Release/oatpp.lib ../../../../GUI/GUI/oatpp/ + cmake.exe --build . -j $NPROC --config $release + cp src/$release/oatpp.lib ../../../../GUI/GUI/oatpp/ cp -Recurse ../src/oatpp/* ../../../../GUI/GUI/oatpp/ popd > $null popd > $null diff --git a/GUI/package.ps1 b/GUI/package.ps1 index fa9eee4..7e5d2e9 100644 --- a/GUI/package.ps1 +++ b/GUI/package.ps1 @@ -1,7 +1,11 @@ param(
- [switch]$skip_zip = $false
+ [switch]$skip_zip = $false,
+ [string]$release = "Release"
)
+echo "Skip zip: $skip_zip"
+echo "Release: $release"
+
$install_dir = "TaSTT"
if (Test-Path $install_dir) {
@@ -80,7 +84,7 @@ cp -Recurse ../Scripts TaSTT/Resources/Scripts cp -Recurse ../Shaders TaSTT/Resources/Shaders
cp -Recurse ../Sounds TaSTT/Resources/Sounds
cp -Recurse ../UnityAssets TaSTT/Resources/UnityAssets
-cp GUI/x64/Release/GUI.exe TaSTT/TaSTT.exe
+cp GUI/x64/$release/GUI.exe TaSTT/TaSTT.exe
cp GUI/GUI/Whisper/Whisper.dll TaSTT/Whisper.dll
mkdir TaSTT/Resources/Models
#cp $WHISPER_CHECKPOINT_FILE TaSTT/Resources/Models/
|
