Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "subprojects/april-asr"]
path = subprojects/april-asr
url = https://github.com/abb128/april-asr.git
url = https://github.com/Techlm77/april-asr.git
3 changes: 2 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
project('livecaptions', 'c',
project('livecaptions', 'c', 'cpp',
version: '0.1.0',
meson_version: '>= 0.59.0',
default_options: [ 'warning_level=2',
'werror=false',
'c_std=gnu11',
'cpp_std=c++17',
],
)

Expand Down
5 changes: 4 additions & 1 deletion src/asrproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ static void april_result_handler(void* userdata, AprilResultType result, size_t
if((data->window == NULL) || (data->pause)) return;

switch(result) {
case APRIL_RESULT_UNKNOWN:
break;

case APRIL_RESULT_RECOGNITION_PARTIAL:
case APRIL_RESULT_RECOGNITION_FINAL:
{
Expand Down Expand Up @@ -257,7 +260,7 @@ bool asr_thread_update_model(asr_thread data, const char *model_path) {

AprilConfig config = {
.handler = april_result_handler,
.flags = APRIL_CONFIG_FLAG_ASYNC_RT_BIT,
.flags = APRIL_CONFIG_FLAG_ASYNC_NO_RT_BIT,
.userdata = data
};

Expand Down
5 changes: 5 additions & 0 deletions src/audiocap-pa.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static void stream_success_cb(pa_stream *stream, int success, void *userdata);
static void stream_read_cb(pa_stream *stream, size_t nbytes, void *userdata);

static void server_info_callback(pa_context *c, const pa_server_info *i, void *userdata){
(void)c;
audio_thread_pa data = (audio_thread_pa)userdata;

data->source_name = (char *)calloc(1, strlen(i->default_source_name) + 1);
Expand Down Expand Up @@ -154,11 +155,13 @@ void *run_audio_thread_pa(void *userdata) {
}

static void context_state_cb(pa_context* context, void* userdata) {
(void)context;
audio_thread_pa data = userdata;
pa_threaded_mainloop_signal(data->mainloop, 0);
}

static void stream_state_cb(pa_stream *s, void *userdata) {
(void)s;
audio_thread_pa data = userdata;
pa_threaded_mainloop_signal(data->mainloop, 0);
}
Expand Down Expand Up @@ -196,6 +199,8 @@ static void stream_read_cb(pa_stream *stream, size_t nbytes, void *userdata) {
}

static void stream_success_cb(pa_stream *stream, int success, void *userdata) {
(void)stream;
(void)success;
audio_thread_pa data = userdata;
pa_threaded_mainloop_signal(data->mainloop, 0);
}
Expand Down
6 changes: 0 additions & 6 deletions src/audiocap.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ struct audio_thread_i {
};


static void *run_audio_thread(void *userdata) {
audio_thread data = (audio_thread)userdata;

return NULL;
}

audio_thread create_audio_thread(bool microphone, asr_thread asr){
audio_thread data = calloc(1, sizeof(struct audio_thread_i));

Expand Down
2 changes: 1 addition & 1 deletion src/history.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void commit_tokens_to_current_history(const AprilToken *tokens,
struct history_token *token = &entry->tokens[i];

if(strlen(tokens[i].token) >= HISTORY_TOKEN_MAX_CHARS){
printf("Token %s is too long! (%d)\n", tokens[i].token, strlen(tokens[i].token));
printf("Token %s is too long! (%zu)\n", tokens[i].token, strlen(tokens[i].token));
g_assert(false);
}

Expand Down
4 changes: 2 additions & 2 deletions src/line-gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void line_generator_update(struct line_generator *lg, size_t num_tokens, const A
// break line if too long
if(i == lg->current_line){
curr->len += line_generator_get_text_width(lg, token);
if(curr->len >= lg->max_text_width) {
if (lg->max_text_width > 0 && curr->len >= (size_t)lg->max_text_width) {
size_t tgt_brk = j;
// find previous word boundary
while((!(tokens[tgt_brk].flags & APRIL_TOKEN_FLAG_WORD_BOUNDARY_BIT)) && (tgt_brk > start_of_line)) tgt_brk--;
Expand Down Expand Up @@ -342,7 +342,7 @@ const char *line_generator_get_plaintext(struct line_generator *lg) {
} else {
// HACK: We need to remove the <span...></span> tags
bool inside_markup = false;
for(int j=0; j<curr->head; j++) {
for(size_t j=0; j<curr->head; j++) {
if(curr->text[j] == '<') {
inside_markup = true;
continue;
Expand Down
13 changes: 7 additions & 6 deletions src/livecaptions-application.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static gboolean on_handle_allow_keep_above(DBLCapNetSapplesLiveCaptionsExternal
GDBusMethodInvocation *invocation,
gpointer user_data)
{
LiveCaptionsApplication *self = LIVECAPTIONS_APPLICATION(user_data);
(void)user_data;

override_keep_above_system(true);

Expand All @@ -130,7 +130,7 @@ static gboolean on_handle_allow_keep_above(DBLCapNetSapplesLiveCaptionsExternal
static gboolean
livecaptions_application_dbus_register(GApplication *app,
GDBusConnection *connection,
const gchar *object_path,
G_GNUC_UNUSED const gchar *object_path,
GError **error)
{
LiveCaptionsApplication *self = LIVECAPTIONS_APPLICATION(app);
Expand Down Expand Up @@ -172,6 +172,8 @@ livecaptions_application_dbus_unregister(GApplication *app,
GDBusConnection *connection,
const gchar *object_path)
{
(void)connection;
(void)object_path;
LiveCaptionsApplication *self = LIVECAPTIONS_APPLICATION(app);

g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(self->dbus_external));
Expand Down Expand Up @@ -242,12 +244,11 @@ livecaptions_application_show_preferences(G_GNUC_UNUSED GSimpleAction *action,
LiveCaptionsApplication *self = LIVECAPTIONS_APPLICATION(user_data);
if(self->welcome != NULL) return;

GtkApplication *app = GTK_APPLICATION(user_data);
GtkWindow *window = gtk_application_get_active_window (app);
LiveCaptionsSettings *preferences = g_object_new(LIVECAPTIONS_TYPE_SETTINGS, "application", GTK_APPLICATION(self), NULL);
LiveCaptionsSettings *preferences = g_object_new(LIVECAPTIONS_TYPE_SETTINGS, NULL);
preferences->application = self;

gtk_window_present (GTK_WINDOW (preferences));
// No parent, so the preferences open in their own window instead of inside the captions bar
adw_dialog_present(ADW_DIALOG(preferences), NULL);

}

Expand Down
72 changes: 28 additions & 44 deletions src/livecaptions-history-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ static gboolean close_self_window(gpointer userdata) {
return G_SOURCE_REMOVE;
}

static void message_cb(AdwMessageDialog *dialog, gchar *response, gpointer userdata){
static void message_cb(AdwAlertDialog *dialog, gchar *response, gpointer userdata){
(void)dialog;
if(g_str_equal(response, "delete")){
erase_all_history();

Expand All @@ -48,26 +49,24 @@ static void message_cb(AdwMessageDialog *dialog, gchar *response, gpointer userd
}

static void warn_deletion_cb(LiveCaptionsHistoryWindow *self){
GtkWindow *parent = GTK_WINDOW(gtk_widget_get_root(GTK_WIDGET(self)));
GtkWidget *dialog;
AdwDialog *dialog;

dialog = adw_message_dialog_new(parent,
_("Erase History?"),
_("Everything in history will be erased. You may wish to export your history before erasing!"));
dialog = adw_alert_dialog_new(_("Erase History?"),
_("Everything in history will be erased. You may wish to export your history before erasing!"));

adw_message_dialog_add_responses(ADW_MESSAGE_DIALOG(dialog),
"cancel", _("_Cancel"),
"delete", _("_Erase Everything"),
NULL);
adw_alert_dialog_add_responses(ADW_ALERT_DIALOG(dialog),
"cancel", _("_Cancel"),
"delete", _("_Erase Everything"),
NULL);

adw_message_dialog_set_response_appearance(ADW_MESSAGE_DIALOG(dialog), "delete", ADW_RESPONSE_DESTRUCTIVE);
adw_alert_dialog_set_response_appearance(ADW_ALERT_DIALOG(dialog), "delete", ADW_RESPONSE_DESTRUCTIVE);

adw_message_dialog_set_default_response(ADW_MESSAGE_DIALOG(dialog), "cancel");
adw_message_dialog_set_close_response(ADW_MESSAGE_DIALOG(dialog), "cancel");
adw_alert_dialog_set_default_response(ADW_ALERT_DIALOG(dialog), "cancel");
adw_alert_dialog_set_close_response(ADW_ALERT_DIALOG(dialog), "cancel");

g_signal_connect(ADW_MESSAGE_DIALOG(dialog), "response", G_CALLBACK(message_cb), self);
g_signal_connect(ADW_ALERT_DIALOG(dialog), "response", G_CALLBACK(message_cb), self);

gtk_window_present(GTK_WINDOW(dialog));
adw_dialog_present(dialog, GTK_WIDGET(self));
}


Expand Down Expand Up @@ -232,50 +231,35 @@ static void load_more_cb(LiveCaptionsHistoryWindow *self) {
}


static void on_save_response(GtkNativeDialog *native,
int response,
LiveCaptionsHistoryWindow *self)
static void on_save_response(GObject *source,
GAsyncResult *result,
gpointer user_data)
{
if(response == GTK_RESPONSE_ACCEPT){
GtkFileChooser *chooser = GTK_FILE_CHOOSER(native);
LiveCaptionsHistoryWindow *self = LIVECAPTIONS_HISTORY_WINDOW(user_data);

g_autoptr(GFile) file = gtk_file_chooser_get_file(chooser);
g_autoptr(GFile) file = gtk_file_dialog_save_finish(GTK_FILE_DIALOG(source), result, NULL);
if(file != NULL){
char *path = g_file_get_path(file);

export_history_as_text(path);

char *uri = g_file_get_uri(file);

gtk_show_uri(GTK_WINDOW(self), uri, GDK_CURRENT_TIME);
g_autoptr(GtkFileLauncher) launcher = gtk_file_launcher_new(file);
gtk_file_launcher_launch(launcher, GTK_WINDOW(self), NULL, NULL, NULL);

g_free(path);
g_free(uri);
}

g_object_unref(native);
g_object_unref(self);
}

static void export_cb(LiveCaptionsHistoryWindow *self) {
GtkFileChooserNative *native;
GtkFileChooser *chooser;
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;

native = gtk_file_chooser_native_new("Export History",
GTK_WINDOW(self),
action,
_("_Export"),
_("_Cancel"));

chooser = GTK_FILE_CHOOSER(native);

gtk_file_chooser_set_current_name(chooser, _("Live Captions History.txt"));
g_autoptr(GtkFileDialog) dialog = gtk_file_dialog_new();

gtk_native_dialog_show(GTK_NATIVE_DIALOG(native));
gtk_file_dialog_set_title(dialog, "Export History");
gtk_file_dialog_set_accept_label(dialog, _("_Export"));
gtk_file_dialog_set_initial_name(dialog, _("Live Captions History.txt"));

g_signal_connect(native, "response",
G_CALLBACK (on_save_response),
self);
gtk_file_dialog_save(dialog, GTK_WINDOW(self), NULL, on_save_response, g_object_ref(self));
}

// The window needs to be kept on top if the main window is kept on top,
Expand Down
Loading