From 6de8bab8d9409fa3c294cf2cca328ae8c9ba13ba Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 21 May 2022 07:42:02 +0200 Subject: [PATCH 1/2] Build against stt It was dropped by Mozilla so some of the responsible employees launched a startup. Currently targeting 0.9.3, which is API compatible with the original Deepspeech. --- src/Makefile.am | 2 +- src/gstdeepspeech.cc | 17 ++++++++--------- src/gstdeepspeech.h | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index b371ddd..4a8aa7e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,6 +2,6 @@ plugin_LTLIBRARIES = libgstdeepspeech.la libgstdeepspeech_la_SOURCES = gstdeepspeech.cc gstdeepspeech.h libgstdeepspeech_la_CXXFLAGS = $(GST_CFLAGS) libgstdeepspeech_la_LIBADD = $(GST_LIBS) -libgstdeepspeech_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) -ldeepspeech +libgstdeepspeech_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) -lstt libgstdeepspeech_la_LIBTOOLFLAGS = --tag=disable-static noinst_HEADERS = gstdeepspeech.h diff --git a/src/gstdeepspeech.cc b/src/gstdeepspeech.cc index 1694416..eb4d853 100644 --- a/src/gstdeepspeech.cc +++ b/src/gstdeepspeech.cc @@ -60,7 +60,6 @@ #endif #include -#include #include #include @@ -132,8 +131,8 @@ gpointer run_model_async(void * instance_data, void * pool_data) g_mutex_lock(&mutex); void *data = malloc(sizeof(short) * info.size); memcpy(data, info.data, info.size); - DS_FeedAudioContent(deepspeech->streaming_state, (const short *) data, (unsigned int) info.size); - result = DS_IntermediateDecode(deepspeech->streaming_state); + STT_FeedAudioContent(deepspeech->streaming_state, (const short *) data, (unsigned int) info.size); + result = STT_IntermediateDecode(deepspeech->streaming_state); g_mutex_unlock(&mutex); if (strlen(result) > 0) { @@ -154,8 +153,8 @@ void process_final_text(GstDeepSpeech * deepspeech, GstBuffer *buf) { gst_buffer_map(buf, &info, GST_MAP_READ); void *data = malloc(sizeof(short) * info.size); memcpy(data, info.data, info.size); - DS_FeedAudioContent(deepspeech->streaming_state, (const short *) data, (unsigned int) info.size); - result = DS_FinishStream(deepspeech->streaming_state); + STT_FeedAudioContent(deepspeech->streaming_state, (const short *) data, (unsigned int) info.size); + result = STT_FinishStream(deepspeech->streaming_state); if (strlen(result) > 0) { GstMessage *msg = gst_deepspeech_message_new (deepspeech, buf, result, false); @@ -249,21 +248,21 @@ gst_deepspeech_init (GstDeepSpeech * deepspeech) static void gst_deepspeech_load_model (GstDeepSpeech * deepspeech) { - int status = DS_CreateModel(deepspeech->speech_model_path, &deepspeech->model_state); + int status = STT_CreateModel(deepspeech->speech_model_path, &deepspeech->model_state); if (status != 0) { fprintf(stderr, "Could not create model.\n"); return; } - DS_SetModelBeamWidth(deepspeech->model_state, DEFAULT_BEAM_WIDTH); + STT_SetModelBeamWidth(deepspeech->model_state, DEFAULT_BEAM_WIDTH); - status = DS_EnableExternalScorer(deepspeech->model_state, deepspeech->scorer_path); + status = STT_EnableExternalScorer(deepspeech->model_state, deepspeech->scorer_path); if (status != 0) { fprintf(stderr, "Could not enable scorer.\n"); return; } - status = DS_CreateStream(deepspeech->model_state, &deepspeech->streaming_state); + status = STT_CreateStream(deepspeech->model_state, &deepspeech->streaming_state); if (status != 0) { fprintf(stderr, "Could not create stream.\n"); return; diff --git a/src/gstdeepspeech.h b/src/gstdeepspeech.h index 9f15fdf..c41c25f 100644 --- a/src/gstdeepspeech.h +++ b/src/gstdeepspeech.h @@ -46,7 +46,7 @@ #include #include -#include "deepspeech.h" +#include G_BEGIN_DECLS From 7280b119047cf47391fe1aff8e9ce246c82742ce Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 21 May 2022 07:43:48 +0200 Subject: [PATCH 2/2] Add Meson build system GStreamer switched to Meson a while ago and building with it is much faster. --- meson.build | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ src/meson.build | 28 +++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 meson.build create mode 100644 src/meson.build diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..a6f5a8e --- /dev/null +++ b/meson.build @@ -0,0 +1,55 @@ +project( + 'gst-deepspeech', + 'cpp', + version: '1.4.0', + license: 'LGPL-2.0-or-later', + meson_version: '>= 0.58', +) + +# Dependencies + +cxx = meson.get_compiler('cpp') + +gst_min_version = '1.0.0' +gst_not_found_message = ''' + You need to install or upgrade the GStreamer development + packages on your system. On debian-based systems these are + libgstreamer1.0-dev and libgstreamer-plugins-base1.0-dev. + on RPM-based systems gstreamer1.0-devel, libgstreamer1.0-devel + or similar. The minimum version required is @0@. +'''.format(gst_min_version) + +gstreamer = dependency( + 'gstreamer-1.0', + version: '>= ' + gst_min_version, + not_found_message: gst_not_found_message +) +gstreamer_base = dependency( + 'gstreamer-base-1.0', + version: '>= ' + gst_min_version, + not_found_message: gst_not_found_message +) +gstreamer_controller = dependency( + 'gstreamer-controller-1.0', + version: '>= ' + gst_min_version, + not_found_message: gst_not_found_message +) +gstreamer_audio = dependency( + 'gstreamer-audio-1.0', + version: '>= ' + gst_min_version, + not_found_message: gst_not_found_message +) + +stt = cxx.find_library('stt') + +# Paths + +prefix = get_option('prefix') +libdir = prefix / get_option('libdir') + +plugins_install_dir = gstreamer.get_variable( + 'pluginsdir', + pkgconfig_define: ['libdir', libdir], +) + +subdir('src') diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..e337f81 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,28 @@ +cdata = configuration_data() +cdata.set_quoted('VERSION', meson.project_version()) +cdata.set_quoted('PACKAGE', meson.project_name()) + +config_h = configure_file( + output: 'config.h', + configuration: cdata, +) + +libgstdeepspeech = shared_library( + 'gstdeepspeech', + sources: [ + 'gstdeepspeech.cc', + config_h, + ], + cpp_args: [ + '-DHAVE_CONFIG_H', + ], + dependencies: [ + gstreamer, + gstreamer_base, + gstreamer_controller, + gstreamer_audio, + stt, + ], + install: true, + install_dir: plugins_install_dir, +)