libvstfdetect/vs_vad.cc
/// SAMPLES MUST BE A MULTIPLE OF 160 bytes.
SAMPLES MUST BE A MULTIPLE OF 160 bytes.
SAMPLES MUST BE A MULTIPLE OF 160 bytes .
int VsVadDetector::ProcessAudio(int16_t* samples, uint32_t nb_samples,
                                float* is_speech) {
  long frames[2] = {0, 0};
  int vadres;
  uint32_t nb_10ms_frames = nb_samples / 160;
  for (uint32_t i = 0; i < nb_10ms_frames; i++) {
    vadres = fvad_process(_fvad, &samples[160 * i], 160);
    if (vadres < 0) {
      std::cerr << "VAD processing failed" << std::endl;
      return -1;
    }
    vadres = !!vadres;  
    frames[vadres]++;   
  }
  if (frames[1] == 0)
    *is_speech = 0.0f;
  else {
    *is_speech = 100.0 * ((double)frames[1] / (double)nb_10ms_frames);
  }
  return 0;
}
int VsVadDetector :: ProcessAudio ( int16_t * samples , uint32_t nb_samples , float * is_speech ) { long frames [ 2 ] = { 0 , 0 } ; int vadres ; uint32_t nb_10ms_frames = nb_samples / 160 ; for ( uint32_t i = 0 ; i < nb_10ms_frames ; i ++ ) { vadres = fvad_process ( _fvad , & samples [ 160 * i ] , 160 ) ; if ( vadres < 0 ) { std :: cerr << " " << std :: endl ; return -1 ; } vadres = ! ! vadres ; frames [ vadres ] ++ ; } if ( frames [ 1 ] == 0 ) * is_speech = 0.0f ; else { * is_speech = 100.0 * ( ( double ) frames [ 1 ] / ( double ) nb_10ms_frames ) ; } return 0 ; }
SAMPLES MUST BE A MULTIPLE OF 160 bytes.
SAMPLES MUST BE A MULTIPLE OF 160 bytes .
// make sure it is 0 or 1 // frames[0] => silence, frames[1] => speech