diff --git a/ext/speex/gstspeexenc.c b/ext/speex/gstspeexenc.c
index 4a0bba6..57dc41c 100644
--- a/ext/speex/gstspeexenc.c
+++ b/ext/speex/gstspeexenc.c
@@ -901,7 +901,7 @@ gst_speex_enc_encode (GstSpeexEnc * enc, gboolean flush)
 
   while (gst_adapter_available (enc->adapter) >= bytes) {
     gint16 *data;
-    gint outsize, written;
+    gint outsize, written, dtx_ret;
     GstBuffer *outbuf;
 
     data = (gint16 *) gst_adapter_take (enc->adapter, bytes);
@@ -913,7 +913,7 @@ gst_speex_enc_encode (GstSpeexEnc * enc, gboolean flush)
     if (enc->channels == 2) {
       speex_encode_stereo_int (data, frame_size, &enc->bits);
     }
-    speex_encode_int (enc->state, data, &enc->bits);
+    dtx_ret = speex_encode_int (enc->state, data, &enc->bits);
 
     g_free (data);
 
@@ -937,6 +937,9 @@ gst_speex_enc_encode (GstSpeexEnc * enc, gboolean flush)
     g_assert (written == outsize);
     speex_bits_reset (&enc->bits);
 
+    if (!dtx_ret)
+      GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_GAP);
+
     GST_BUFFER_TIMESTAMP (outbuf) = enc->start_ts +
         gst_util_uint64_scale_int ((enc->frameno_out -
             enc->nframes) * frame_size - enc->lookahead, GST_SECOND, enc->rate);
diff --git a/gst/rtp/gstrtpspeexpay.c b/gst/rtp/gstrtpspeexpay.c
index a551fa9..35273e2 100644
--- a/gst/rtp/gstrtpspeexpay.c
+++ b/gst/rtp/gstrtpspeexpay.c
@@ -260,6 +260,11 @@ gst_rtp_speex_pay_handle_buffer (GstBaseRTPPayload * basepayload,
       break;
   }
 
+  if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_GAP)) {
+    ret = GST_FLOW_OK;
+    goto done;
+  }
+
   timestamp = GST_BUFFER_TIMESTAMP (buffer);
   duration = GST_BUFFER_DURATION (buffer);
 
