mirror of
https://github.com/occ-ai/obs-localvocal
synced 2024-11-07 18:57:14 +00:00
remove lambda callback
This commit is contained in:
parent
60a3cf0364
commit
de346a2897
@ -73,4 +73,6 @@ struct transcription_filter_audio_info {
|
|||||||
uint64_t timestamp;
|
uint64_t timestamp;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void set_text_callback(struct transcription_filter_data *gf, const std::string &str);
|
||||||
|
|
||||||
#endif /* TRANSCRIPTION_FILTER_DATA_H */
|
#endif /* TRANSCRIPTION_FILTER_DATA_H */
|
||||||
|
@ -174,6 +174,35 @@ void acquire_weak_text_source_ref(struct transcription_filter_data *gf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_text_callback(struct transcription_filter_data *gf, const std::string &str)
|
||||||
|
{
|
||||||
|
if (!gf->text_source_mutex) {
|
||||||
|
obs_log(LOG_ERROR, "text_source_mutex is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gf->text_source) {
|
||||||
|
// attempt to acquire a weak ref to the text source if it's yet available
|
||||||
|
acquire_weak_text_source_ref(gf);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(*gf->text_source_mutex);
|
||||||
|
|
||||||
|
if (!gf->text_source) {
|
||||||
|
obs_log(LOG_ERROR, "text_source is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto target = obs_weak_source_get_source(gf->text_source);
|
||||||
|
if (!target) {
|
||||||
|
obs_log(LOG_ERROR, "text_source target is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto text_settings = obs_source_get_settings(target);
|
||||||
|
obs_data_set_string(text_settings, "text", str.c_str());
|
||||||
|
obs_source_update(target, text_settings);
|
||||||
|
obs_source_release(target);
|
||||||
|
};
|
||||||
|
|
||||||
void transcription_filter_update(void *data, obs_data_t *s)
|
void transcription_filter_update(void *data, obs_data_t *s)
|
||||||
{
|
{
|
||||||
struct transcription_filter_data *gf =
|
struct transcription_filter_data *gf =
|
||||||
@ -364,36 +393,6 @@ void *transcription_filter_create(obs_data_t *settings, obs_source_t *filter)
|
|||||||
gf->text_source = nullptr;
|
gf->text_source = nullptr;
|
||||||
gf->text_source_name = nullptr;
|
gf->text_source_name = nullptr;
|
||||||
|
|
||||||
obs_log(LOG_INFO, "transcription_filter: setup callback");
|
|
||||||
// set the callback to set the text in the output text source (subtitles)
|
|
||||||
gf->setTextCallback = [gf](const std::string &str) {
|
|
||||||
if (!gf->text_source_mutex) {
|
|
||||||
obs_log(LOG_ERROR, "text_source_mutex is null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!gf->text_source) {
|
|
||||||
// attempt to acquire a weak ref to the text source if it's yet available
|
|
||||||
acquire_weak_text_source_ref(gf);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(*gf->text_source_mutex);
|
|
||||||
|
|
||||||
if (!gf->text_source) {
|
|
||||||
obs_log(LOG_ERROR, "text_source is null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto target = obs_weak_source_get_source(gf->text_source);
|
|
||||||
if (!target) {
|
|
||||||
obs_log(LOG_ERROR, "text_source target is null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto text_settings = obs_source_get_settings(target);
|
|
||||||
obs_data_set_string(text_settings, "text", str.c_str());
|
|
||||||
obs_source_update(target, text_settings);
|
|
||||||
obs_source_release(target);
|
|
||||||
};
|
|
||||||
|
|
||||||
obs_log(LOG_INFO, "transcription_filter: run update");
|
obs_log(LOG_INFO, "transcription_filter: run update");
|
||||||
// get the settings updated on the filter data struct
|
// get the settings updated on the filter data struct
|
||||||
transcription_filter_update(gf, settings);
|
transcription_filter_update(gf, settings);
|
||||||
|
@ -254,16 +254,16 @@ void process_audio_from_buffer(struct transcription_filter_data *gf)
|
|||||||
|
|
||||||
if (inference_result.result == DETECTION_RESULT_SPEECH) {
|
if (inference_result.result == DETECTION_RESULT_SPEECH) {
|
||||||
// output inference result to a text source
|
// output inference result to a text source
|
||||||
gf->setTextCallback(inference_result.text);
|
set_text_callback(gf, inference_result.text);
|
||||||
} else if (inference_result.result == DETECTION_RESULT_SILENCE) {
|
} else if (inference_result.result == DETECTION_RESULT_SILENCE) {
|
||||||
// output inference result to a text source
|
// output inference result to a text source
|
||||||
gf->setTextCallback("[silence]");
|
set_text_callback(gf, "[silence]");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (gf->log_words) {
|
if (gf->log_words) {
|
||||||
obs_log(LOG_INFO, "skipping inference");
|
obs_log(LOG_INFO, "skipping inference");
|
||||||
}
|
}
|
||||||
gf->setTextCallback("");
|
set_text_callback(gf, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
// end of timer
|
// end of timer
|
||||||
|
Loading…
Reference in New Issue
Block a user