Skip to content

Commit

Permalink
refactor: Prevent duplicate translation of sentences in send_sentence…
Browse files Browse the repository at this point in the history
…_to_translation (#145)
  • Loading branch information
royshil authored Jul 30, 2024
1 parent 4e2f3de commit 87c5a0a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/transcription-filter-callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,16 @@ void send_caption_to_stream(DetectionResultWithText result, const std::string &s
obs_output_t *streaming_output = obs_frontend_get_streaming_output();
if (streaming_output) {
// calculate the duration in seconds
const uint64_t duration = result.end_timestamp_ms - result.start_timestamp_ms;
obs_log(gf->log_level, "Sending caption to streaming output: %s", str_copy.c_str());
const double duration =
(double)(result.end_timestamp_ms - result.start_timestamp_ms) / 1000.0;
// prevent the duration from being too short or too long
const double effective_duration = std::min(std::max(2.0, duration), 7.0);
obs_log(gf->log_level,
"Sending caption to streaming output: %s (raw duration %.3f, effective duration %.3f)",
str_copy.c_str(), duration, effective_duration);
// TODO: find out why setting short duration does not work
obs_output_output_caption_text2(streaming_output, str_copy.c_str(),
(double)duration / 1000.0);
effective_duration);
obs_output_release(streaming_output);
}
}
Expand Down Expand Up @@ -259,6 +265,7 @@ void set_text_callback(struct transcription_filter_data *gf,
}

if (gf->caption_to_stream && result.result == DETECTION_RESULT_SPEECH) {
// TODO: add support for partial transcriptions
send_caption_to_stream(result, str_copy, gf);
}

Expand Down

0 comments on commit 87c5a0a

Please sign in to comment.