Skip to content

Commit

Permalink
Add new listen property to allow the detector to be bypassed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Liam Wickins committed Apr 14, 2021
1 parent f7e5e88 commit db76e9f
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions examples/C++/gstreamer/gst-snowboy/gst-plugin/src/gstsnowboy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extern "C" {

}

#include "../../../../gstreamer/gst-snowboy/gst-plugin/src/snowboy-detect.h"
#include "snowboy-detect.h"

GST_DEBUG_CATEGORY_STATIC (snowboy_debug);
#define GST_CAT_DEFAULT snowboy_debug
Expand All @@ -106,6 +106,7 @@ struct _GstSnowboy
gchar *models;
gchar *sensitivity;
gfloat gain;
gboolean listen;

// Detector instance
snowboy::SnowboyDetect *detector;
Expand All @@ -124,7 +125,8 @@ enum
PROP_MODELS,
PROP_RESOURCE,
PROP_SENSITIVITY,
PROP_GAIN
PROP_GAIN,
PROP_LISTEN,
};

G_DEFINE_TYPE (GstSnowboy, gst_snowboy,
Expand Down Expand Up @@ -181,10 +183,15 @@ gst_snowboy_class_init (GstSnowboyClass * klass)
G_PARAM_READWRITE));

g_object_class_install_property (gobject_class, PROP_GAIN,
g_param_spec_float ("gain", "Audio gain", "Floating point value",
g_param_spec_float ("gain", "Audio gain", "Input gain at detector",
0.0, 1.0, 1.0,
G_PARAM_READWRITE));

g_object_class_install_property (gobject_class, PROP_LISTEN,
g_param_spec_boolean ("listen", "Detector listen on/off", "Indicates whether detector is listening or not",
TRUE,
G_PARAM_READWRITE));

// Signals
gst_snowboy_signals[HOTWORD_DETECT_SIGNAL] = g_signal_new ("hotword-detect", G_TYPE_FROM_CLASS(klass),
G_SIGNAL_RUN_LAST,
Expand Down Expand Up @@ -227,6 +234,7 @@ gst_snowboy_init (GstSnowboy * snowboy)
snowboy->models = g_strdup("resources/models/snowboy.umdl");
snowboy->sensitivity = g_strdup("0.5");
snowboy->gain = 1.0;
snowboy->listen = true;
}

static void gst_snowboy_finalize (GObject * obj)
Expand Down Expand Up @@ -269,6 +277,9 @@ gst_snowboy_set_property (GObject * object, guint prop_id,
case PROP_GAIN:
snowboy->gain = g_value_get_float (value);
break;
case PROP_LISTEN:
snowboy->listen = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
Expand Down Expand Up @@ -296,6 +307,9 @@ gst_snowboy_get_property (GObject * object, guint prop_id,
case PROP_GAIN:
g_value_set_float (value, snowboy->gain);
break;
case PROP_LISTEN:
g_value_set_boolean (value, snowboy->listen);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
Expand Down Expand Up @@ -360,11 +374,15 @@ gst_snowboy_filter (GstBaseTransform * base_transform,
memcpy (map_out.data, map_in.data, map_out.size);
gst_buffer_unmap (outbuf, &map_out);
}
int result = snowboy->detector->RunDetection((const int16_t* const)map_in.data, map_in.size / 2);
if (result > 0) {
GST_INFO_OBJECT (snowboy, "model index: %d", result - 1);
g_signal_emit (G_OBJECT (snowboy), gst_snowboy_signals[HOTWORD_DETECT_SIGNAL], 0, result - 1);

if (snowboy->listen) {
int result = snowboy->detector->RunDetection((const int16_t* const)map_in.data, map_in.size / 2);
if (result > 0) {
GST_INFO_OBJECT (snowboy, "model index: %d", result - 1);
g_signal_emit (G_OBJECT (snowboy), gst_snowboy_signals[HOTWORD_DETECT_SIGNAL], 0, result - 1);
}
}

gst_buffer_unmap (inbuf, &map_in);
}

Expand Down

0 comments on commit db76e9f

Please sign in to comment.