Skip to content

Commit

Permalink
Clear final lines after 6 seconds of silence
Browse files Browse the repository at this point in the history
  • Loading branch information
abb128 committed Oct 4, 2023
1 parent 1cb6a52 commit c6b7e9c
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/asrproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <ctype.h>
#include <sys/mman.h>
#include <glib.h>
#include <time.h>

#include <stdbool.h>
#include <april_api.h>
Expand Down Expand Up @@ -59,13 +60,35 @@ struct asr_thread_i {
volatile bool text_stream_active;
volatile bool pause;

volatile time_t last_silence_time;

volatile bool ending;

bool errored;
};


static void *run_asr_thread(void *userdata) {
static gboolean main_thread_update_label(void *userdata);

static void *run_asr_thread(void *userdata){
asr_thread data = (asr_thread)userdata;

while(!data->ending){
sleep(1);

if(data->last_silence_time == 0) continue;

time_t current_time = time(NULL);

if(difftime(current_time, data->last_silence_time) >= 6.0) {
g_mutex_lock(&data->text_mutex);
data->last_silence_time = 0;
for(int i=1; i<AC_LINE_COUNT; i++) line_generator_break(&data->line);
g_mutex_unlock(&data->text_mutex);
g_idle_add(main_thread_update_label, data);
}
}

//sleep(40);

//if(data->sound_counter < 512) {
Expand Down Expand Up @@ -102,6 +125,7 @@ static void april_result_handler(void* userdata, AprilResultType result, size_t
case APRIL_RESULT_RECOGNITION_FINAL:
{
g_mutex_lock(&data->text_mutex);
data->last_silence_time = 0;

if((data->layout_counter != data->window->font_layout_counter) || (data->line.layout == NULL)) {
if(data->line.layout != NULL) g_object_unref(data->line.layout);
Expand Down Expand Up @@ -130,6 +154,7 @@ static void april_result_handler(void* userdata, AprilResultType result, size_t

case APRIL_RESULT_SILENCE: {
g_mutex_lock(&data->text_mutex);
data->last_silence_time = time(NULL);

line_generator_break(&data->line);
save_silence_to_history();
Expand Down Expand Up @@ -273,6 +298,7 @@ bool asr_thread_update_model(asr_thread data, const char *model_path) {
data->session = new_session;

data->errored = false;
data->ending = false;
data->pause = false;

line_generator_finalize(&data->line);
Expand All @@ -296,6 +322,8 @@ void asr_thread_flush(asr_thread thread) {
}

void free_asr_thread(asr_thread thread) {
thread->ending = true;

g_mutex_lock(&thread->text_mutex);

g_thread_join(thread->thread_id);
Expand Down

1 comment on commit c6b7e9c

@shahradelahi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the efforts, but this feature is annoying!

Please sign in to comment.