1 /* 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_AUDIO_PROCESSING_VAD_VOICE_ACTIVITY_DETECTOR_H_ 12 #define MODULES_AUDIO_PROCESSING_VAD_VOICE_ACTIVITY_DETECTOR_H_ 13 14 #include <stddef.h> 15 #include <stdint.h> 16 17 #include <memory> 18 #include <vector> 19 20 #include "common_audio/resampler/include/resampler.h" 21 #include "modules/audio_processing/vad/common.h" 22 #include "modules/audio_processing/vad/pitch_based_vad.h" 23 #include "modules/audio_processing/vad/standalone_vad.h" 24 #include "modules/audio_processing/vad/vad_audio_proc.h" 25 26 namespace webrtc { 27 28 // A Voice Activity Detector (VAD) that combines the voice probability from the 29 // StandaloneVad and PitchBasedVad to get a more robust estimation. 30 class VoiceActivityDetector { 31 public: 32 VoiceActivityDetector(); 33 ~VoiceActivityDetector(); 34 35 // Processes each audio chunk and estimates the voice probability. 36 void ProcessChunk(const int16_t* audio, size_t length, int sample_rate_hz); 37 38 // Returns a vector of voice probabilities for each chunk. It can be empty for 39 // some chunks, but it catches up afterwards returning multiple values at 40 // once. chunkwise_voice_probabilities()41 const std::vector<double>& chunkwise_voice_probabilities() const { 42 return chunkwise_voice_probabilities_; 43 } 44 45 // Returns a vector of RMS values for each chunk. It has the same length as 46 // chunkwise_voice_probabilities(). chunkwise_rms()47 const std::vector<double>& chunkwise_rms() const { return chunkwise_rms_; } 48 49 // Returns the last voice probability, regardless of the internal 50 // implementation, although it has a few chunks of delay. last_voice_probability()51 float last_voice_probability() const { return last_voice_probability_; } 52 53 private: 54 // TODO(aluebs): Change these to float. 55 std::vector<double> chunkwise_voice_probabilities_; 56 std::vector<double> chunkwise_rms_; 57 58 float last_voice_probability_; 59 60 Resampler resampler_; 61 VadAudioProc audio_processing_; 62 63 std::unique_ptr<StandaloneVad> standalone_vad_; 64 PitchBasedVad pitch_based_vad_; 65 66 int16_t resampled_[kLength10Ms]; 67 AudioFeatures features_; 68 }; 69 70 } // namespace webrtc 71 72 #endif // MODULES_AUDIO_PROCESSING_VAD_VOICE_ACTIVITY_DETECTOR_H_ 73