[prev in list] [next in list] [prev in thread] [next in thread] 

List:       asterisk-dev
Subject:    [Asterisk-Dev] Silence detection failing
From:       Juan Jose Comellas <juanjo () comellas ! com ! ar>
Date:       2005-03-31 22:52:13
Message-ID: 200503311952.13869.juanjo () comellas ! com ! ar
[Download RAW message or body]

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@comellas.com.ar)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic