Skip to content

Commit

Permalink
Flatpak build
Browse files Browse the repository at this point in the history
  • Loading branch information
abb128 committed Dec 1, 2022
1 parent bb6745b commit 563e7be
Show file tree
Hide file tree
Showing 14 changed files with 284 additions and 134 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build
build/*
_build
_build/*
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "subprojects/april-asr"]
path = subprojects/april-asr
url = git@github.com:abb128/april-asr.git
38 changes: 36 additions & 2 deletions data/net.sapples.LiveCaptions.gschema.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="livecaptions">
<schema id="net.sapples.LiveCaptions" path="/net/sapples/LiveCaptions/">
</schema>
<schema id='net.sapples.LiveCaptions' path='/net/sapples/LiveCaptions/'>
<key name="font-name" type="s">
<default>'Sans Regular'</default>
<summary>The font of the captions</summary>
</key>

<key name="font-size" type="i">
<range min="1" max="144" />
<default>12</default>
<summary>The font size of the captions</summary>
</key>

<key name="text-uppercase" type="b">
<default>false</default>
<summary>Display letters in uppercase instead of lowercase</summary>
</key>

<key name="fade-text" type="b">
<default>true</default>
<summary>Fade text based on confidence</summary>
</key>

<key name="filter-profanity" type="b">
<default>true</default>
<summary>Filter swear words and slurs</summary>
</key>

<key name="microphone" type="b">
<default>false</default>
<summary>Caption microphone input instead of desktop audio</summary>
</key>

<key name="benchmark" type="d">
<default>-1.0</default>
</key>
</schema>
</schemalist>
5 changes: 5 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ project('livecaptions', 'c',
],
)

cmake = import('cmake')
april = cmake.subproject('april-asr')

april_lib = april.dependency('aprilasr_static')

i18n = import('i18n')

gnome = import('gnome')
Expand Down
41 changes: 40 additions & 1 deletion net.sapples.LiveCaptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"--socket=pulseaudio",
"--socket=wayland",
"--filesystem=xdg-run/pipewire-0:ro",
"--env=LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/app/lib/pipewire-0.3/jack"
"--env=LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/app/lib/pipewire-0.3/jack:/app/lib"
],
"cleanup" : [
"/include",
Expand All @@ -22,10 +22,32 @@
"/share/gtk-doc",
"/share/man",
"/share/pkgconfig",
"/onnxruntime_ROOT",
"*.la",
"*.a"
],
"modules" : [
{
"name" : "onnxruntime",
"buildsystem" : "simple",
"sources" : [
{
"type" : "file",
"dest-filename" : "microsoft.ml.onnxruntime.1.13.1.nupkg",
"url" : "https://globalcdn.nuget.org/packages/microsoft.ml.onnxruntime.1.13.1.nupkg",
"sha256" : "590e655b036e6e663ad1274bf8650ae671859005cd61eff432dfd3dba66b5904"
}
],
"build-commands" : [
"mkdir ${FLATPAK_DEST}/onnxruntime_ROOT",
"mv microsoft.ml.onnxruntime.1.13.1.nupkg ${FLATPAK_DEST}/onnxruntime_ROOT/Microsoft.ML.OnnxRuntime.1.13.1.nupkg",
"cd ${FLATPAK_DEST}/onnxruntime_ROOT && unzip Microsoft.ML.OnnxRuntime.1.13.1.nupkg",

"install -Dm755 ${FLATPAK_DEST}/onnxruntime_ROOT/runtimes/linux-x64/native/libonnxruntime.so ${FLATPAK_DEST}/lib/libonnxruntime.so.1.13.1",
"ln -s ${FLATPAK_DEST}/lib/libonnxruntime.so.1.13.1 ${FLATPAK_DEST}/lib/libonnxruntime.so"
]
},

{
"name" : "livecaptions",
"builddir" : true,
Expand All @@ -36,6 +58,23 @@
"url" : "file:///home/alex/Projects/LiveCaptions"
}
]
},

{
"name": "april-model-v0",
"buildsystem" : "simple",
"sources" : [
{
"type" : "file",
"dest-filename" : "aprilv0_en-us.april",
"url" : "https://april.sapples.net/aprilv0_en-us.april",
"sha256" : "f5a30f888e797769b1b7de143c05d2c92a1702c263b5b71d62fd2028cede5627"
}
],
"build-commands" : [
"mkdir -p ${XDG_DATA_HOME}/LiveCaptions/models",
"install -Dm644 aprilv0_en-us.april ${XDG_DATA_HOME}/LiveCaptions/models"
]
}
]
}
17 changes: 17 additions & 0 deletions src/asrproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "line-gen.h"

struct asr_thread_i {
size_t silence_counter;

FILE *fd;

GThread * thread_id;
Expand Down Expand Up @@ -66,6 +68,21 @@ void april_result_handler(void* userdata, AprilResultType result, size_t count,
}

void asr_thread_enqueue_audio(asr_thread thread, short *data, size_t num_shorts) {
bool found_nonzero = false;
for(int i=0; i<num_shorts; i++){
if((data[i] > 8) || (data[i] < -8)){
found_nonzero = true;
break;
}
}

thread->silence_counter = found_nonzero ? 0 : (thread->silence_counter + num_shorts);

if(thread->silence_counter >= 24000){
thread->silence_counter = 24000;
return aas_flush(thread->session);
}

fwrite(data, num_shorts, 2, thread->fd);
aas_feed_pcm16(thread->session, data, num_shorts); // TODO?
}
Expand Down
93 changes: 92 additions & 1 deletion src/livecaptions-settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <glib/gi18n.h>

#include "livecaptions-config.h"
#include "livecaptions-settings.h"
#include "livecaptions-application.h"
Expand Down Expand Up @@ -48,8 +50,81 @@ toast_show_cb (AdwPreferencesWindow *window)
}


static void issue_tracker_cb(LiveCaptionsSettings *self){
system("xdg-open https://github.com/abb128/LiveCaptions/issues");
}

static void git_cb(LiveCaptionsSettings *self){
system("xdg-open https://github.com/abb128/LiveCaptions");
}

static void about_cb(LiveCaptionsSettings *self) {
GtkRoot *root = gtk_widget_get_root (GTK_WIDGET (self));
GtkWidget *about;

const char *developers[] = {
"abb128",
NULL
};

const char *special_thanks[] = {
"Fangjun Kuang (@csukuangfj) and the k2-fsa/icefall contributors",
NULL
};

//const char *release_notes = "\
// <p>\
// This release adds the following features:\
// </p>\
// <ul>\
// <li>Added a way to export fonts.</li>\
// <li>Better support for <code>monospace</code> fonts.</li>\
// <li>Added a way to preview <em>italic</em> text.</li>\
// <li>Bug fixes and performance improvements.</li>\
// <li>Translation updates.</li>\
// </ul>\
//";

about =
g_object_new (ADW_TYPE_ABOUT_WINDOW,
"transient-for", root,
"application-icon", "net.sapples.LiveCaptions",
"application-name", _("Live Captions"),
"developer-name", _("abb128"),
"version", "0.0.1",
//"release-notes-version", "1.2.0",
//"release-notes", release_notes,
"comments", _("Live Captions is an application for the Linux Desktop that captions desktop audio."),
"website", "https://github.com/abb128/LiveCaptions",
"issue-url", "https://github.com/abb128/LiveCaptions/issues",
//"support-url", "https://example.org",
"copyright", "© 2022 abb128",
"license-type", GTK_LICENSE_GPL_3_0,
"developers", developers,
//"artists", artists,
"translator-credits", _("translator-credits"),
NULL);

//adw_about_window_add_link (ADW_ABOUT_WINDOW (about),
// _("_Documentation"),
// "https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.AboutWindow.html");

adw_about_window_add_legal_section (ADW_ABOUT_WINDOW (about),
_("Model"),
NULL,
GTK_LICENSE_CUSTOM,
"The ASR model was originally trained by Fangjun Kuang (@csukuangfj), and has been finetuned on extra data.");

adw_about_window_add_acknowledgement_section (ADW_ABOUT_WINDOW (about),
_("Special thanks to"),
special_thanks);

gtk_window_present (GTK_WINDOW (about));
}


static void change_font(LiveCaptionsSettings *self) {

}

static void livecaptions_settings_class_init(LiveCaptionsSettingsClass *klass) {
Expand All @@ -59,8 +134,17 @@ static void livecaptions_settings_class_init(LiveCaptionsSettingsClass *klass) {
gtk_widget_class_bind_template_child (widget_class, LiveCaptionsSettings, subpage1);
gtk_widget_class_bind_template_child (widget_class, LiveCaptionsSettings, subpage2);

gtk_widget_class_bind_template_child (widget_class, LiveCaptionsSettings, font_button);
gtk_widget_class_bind_template_child (widget_class, LiveCaptionsSettings, text_upper_switch);
gtk_widget_class_bind_template_child (widget_class, LiveCaptionsSettings, fade_text_switch);
gtk_widget_class_bind_template_child (widget_class, LiveCaptionsSettings, filter_profanity_switch);


gtk_widget_class_bind_template_callback (widget_class, change_font);
gtk_widget_class_bind_template_callback (widget_class, return_to_preferences_cb);
gtk_widget_class_bind_template_callback (widget_class, issue_tracker_cb);
gtk_widget_class_bind_template_callback (widget_class, git_cb);
gtk_widget_class_bind_template_callback (widget_class, about_cb);
gtk_widget_class_bind_template_callback (widget_class, subpage1_activated_cb);
gtk_widget_class_bind_template_callback (widget_class, subpage2_activated_cb);

Expand All @@ -69,4 +153,11 @@ static void livecaptions_settings_class_init(LiveCaptionsSettingsClass *klass) {

static void livecaptions_settings_init(LiveCaptionsSettings *self) {
gtk_widget_init_template(GTK_WIDGET(self));

self->settings = g_settings_new("net.sapples.LiveCaptions");

g_settings_bind(self->settings, "text-uppercase", self->text_upper_switch, "state", G_SETTINGS_BIND_DEFAULT);
g_settings_bind(self->settings, "fade-text", self->fade_text_switch, "state", G_SETTINGS_BIND_DEFAULT);
g_settings_bind(self->settings, "filter-profanity", self->filter_profanity_switch, "state", G_SETTINGS_BIND_DEFAULT);

}
7 changes: 7 additions & 0 deletions src/livecaptions-settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
struct _LiveCaptionsSettings {
AdwPreferencesWindow parent_instance;

GSettings *settings;

GtkFontButton *font_button;
GtkSwitch *text_upper_switch;
GtkSwitch *fade_text_switch;
GtkSwitch *filter_profanity_switch;

GtkWidget *subpage1;
GtkWidget *subpage2;

Expand Down
Loading

0 comments on commit 563e7be

Please sign in to comment.