[Asterisk-Dev] Silence detection failing

Juan Jose Comellas juanjo at comellas.com.ar
Thu Mar 31 15:52:13 MST 2005


I'm trying to use the silence detection APIs from Asterisk while recording 
some audio, but it doesn't seem to be working. I copied some code from the 
Record application (stable branch) and I'm using the exact same code for 
silence detection. The problem is that silence is detected even when i"m 
talking. I'm using 256 as the dsp's threshold. It seems that using a lower 
value for this (64) improves the situation. Could this be the problem? What 
is the recommended value for this?

This is a simplified version of the section of code dealing with silence 
detection:

 struct ast_channel *chan;
 struct ast_frame *f;
        struct ast_dsp *sildet = NULL;      /* silence detector dsp */
        int totalsilence = 0;
        int dspsilence = 0;
 int silence = 5000; /* 5 seconds of silence */

 rfmt = this->channel_->readformat;
 res = ast_set_read_format( this->channel_, AST_FORMAT_SLINEAR );

 sildet = ast_dsp_new();
        ast_dsp_set_threshold( sildet, 256 );

 for ( ;; )
 { 
  /* [wait for frames from channel] */

  f = ast_read( c );
  if ( f != NULL )
  {
   dspsilence = 0;
   ast_dsp_silence( sildet, f, &dspsilence );
   if ( dspsilence )
    totalsilence = dspsilence;
   else
    totalsilence = 0;

   if ( totalsilence > silence )
   {
    ast_log( LOG_DEBUG, "Silence detected on channel %s: detected=%d ms; "
     "max=%d ms\n", this->channel_->name, totalsilence, silence );
    // Ended happily with silence.
    ast_frfree( f );
    break;
   }
  }
  [...]
 }



-- 
Juan Jose Comellas
(juanjo at comellas.com.ar)




More information about the asterisk-dev mailing list