Skip to content

Commit

Permalink
Merge pull request #3 from occ-ai/roy.fix_model_finder_and_initial_load
Browse files Browse the repository at this point in the history
Update model-downloader.cpp and squawk-source.cpp
  • Loading branch information
royshil authored Jun 24, 2024
2 parents bcfc731 + 5da4fe7 commit d8e2240
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
30 changes: 17 additions & 13 deletions src/model-utils/model-downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,29 @@
std::string find_model_folder(const ModelInfo &model_info)
{
char *data_folder_models = obs_module_file("models");
const std::filesystem::path module_data_models_folder =
std::filesystem::absolute(data_folder_models);
bfree(data_folder_models);
if (data_folder_models != nullptr) {
const std::filesystem::path module_data_models_folder =
std::filesystem::absolute(data_folder_models);
bfree(data_folder_models);

const std::string model_local_data_path =
(module_data_models_folder / model_info.local_folder_name).string();
const std::string model_local_data_path =
(module_data_models_folder / model_info.local_folder_name).string();

obs_log(LOG_INFO, "Checking if model '%s' exists in data...",
model_info.friendly_name.c_str());
obs_log(LOG_INFO, "Checking if model '%s' exists in data...",
model_info.friendly_name.c_str());

if (!std::filesystem::exists(model_local_data_path)) {
obs_log(LOG_INFO, "Model not found in data: %s", model_local_data_path.c_str());
} else {
obs_log(LOG_INFO, "Model folder found in data: %s", model_local_data_path.c_str());
return model_local_data_path;
if (!std::filesystem::exists(model_local_data_path)) {
obs_log(LOG_INFO, "Model not found in data: %s",
model_local_data_path.c_str());
} else {
obs_log(LOG_INFO, "Model folder found in data: %s",
model_local_data_path.c_str());
return model_local_data_path;
}
}

// Check if model exists in the config folder
char *config_folder = obs_module_get_config_path(obs_current_module(), "models");
char *config_folder = obs_module_config_path("models");
const std::filesystem::path module_config_models_folder =
std::filesystem::absolute(config_folder);
bfree(config_folder);
Expand Down
4 changes: 3 additions & 1 deletion src/squawk-source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void *squawk_source_create(obs_data_t *settings, obs_source_t *source)
squawk_source_data *squawk_data = new (data) squawk_source_data();

squawk_data->tts_context.callback_data = squawk_data;
squawk_data->tts_context.model_name = "";

squawk_data->context = source;
squawk_data->audioThread = std::make_unique<AudioThread>(source);
Expand Down Expand Up @@ -127,6 +128,8 @@ obs_properties_t *squawk_source_properties(void *data)
UNUSED_PARAMETER(download_status);
obs_log(LOG_INFO, "Model downloaded: %s", path.c_str());
unpack_model(model_info, path);
// Update will initialize the model on the TTS context
squawk_data_->tts_context.model_name = "";
// update the source
obs_data_t *source_settings =
obs_source_get_settings(squawk_data_->context);
Expand Down Expand Up @@ -226,7 +229,6 @@ void squawk_source_update(void *data, obs_data_t *settings)
source = "";
}
squawk_data->inputThread->setOBSTextSource(source);

squawk_data->inputThread->setFile(obs_data_get_string(settings, "file"));

std::string new_model_name = obs_data_get_string(settings, "model");
Expand Down

0 comments on commit d8e2240

Please sign in to comment.