vad.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2014 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. #ifndef COMMON_AUDIO_VAD_INCLUDE_VAD_H_
  11. #define COMMON_AUDIO_VAD_INCLUDE_VAD_H_
  12. #include <memory>
  13. #include "common_audio/vad/include/webrtc_vad.h"
  14. #include "rtc_base/checks.h"
  15. namespace webrtc {
  16. class Vad {
  17. public:
  18. enum Aggressiveness {
  19. kVadNormal = 0,
  20. kVadLowBitrate = 1,
  21. kVadAggressive = 2,
  22. kVadVeryAggressive = 3
  23. };
  24. enum Activity { kPassive = 0, kActive = 1, kError = -1 };
  25. virtual ~Vad() = default;
  26. // Calculates a VAD decision for the given audio frame. Valid sample rates
  27. // are 8000, 16000, and 32000 Hz; the number of samples must be such that the
  28. // frame is 10, 20, or 30 ms long.
  29. virtual Activity VoiceActivity(const int16_t* audio,
  30. size_t num_samples,
  31. int sample_rate_hz) = 0;
  32. // Resets VAD state.
  33. virtual void Reset() = 0;
  34. };
  35. // Returns a Vad instance that's implemented on top of WebRtcVad.
  36. std::unique_ptr<Vad> CreateVad(Vad::Aggressiveness aggressiveness);
  37. } // namespace webrtc
  38. #endif // COMMON_AUDIO_VAD_INCLUDE_VAD_H_