typing_detection.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 MODULES_AUDIO_PROCESSING_TYPING_DETECTION_H_
  11. #define MODULES_AUDIO_PROCESSING_TYPING_DETECTION_H_
  12. #include "rtc_base/system/rtc_export.h"
  13. namespace webrtc {
  14. class RTC_EXPORT TypingDetection {
  15. public:
  16. TypingDetection();
  17. virtual ~TypingDetection();
  18. // Run the detection algortihm. Shall be called every 10 ms. Returns true if
  19. // typing is detected, or false if not, based on the update period as set with
  20. // SetParameters(). See |report_detection_update_period_| description below.
  21. bool Process(bool key_pressed, bool vad_activity);
  22. // Gets the time in seconds since the last detection.
  23. int TimeSinceLastDetectionInSeconds();
  24. // Sets the algorithm parameters. A parameter value of 0 leaves it unchanged.
  25. // See the correspondning member variables below for descriptions.
  26. void SetParameters(int time_window,
  27. int cost_per_typing,
  28. int reporting_threshold,
  29. int penalty_decay,
  30. int type_event_delay,
  31. int report_detection_update_period);
  32. private:
  33. int time_active_;
  34. int time_since_last_typing_;
  35. int penalty_counter_;
  36. // Counter since last time the detection status reported by Process() was
  37. // updated. See also |report_detection_update_period_|.
  38. int counter_since_last_detection_update_;
  39. // The detection status to report. Updated every
  40. // |report_detection_update_period_| call to Process().
  41. bool detection_to_report_;
  42. // What |detection_to_report_| should be set to next time it is updated.
  43. bool new_detection_to_report_;
  44. // Settable threshold values.
  45. // Number of 10 ms slots accepted to count as a hit.
  46. int time_window_;
  47. // Penalty added for a typing + activity coincide.
  48. int cost_per_typing_;
  49. // Threshold for |penalty_counter_|.
  50. int reporting_threshold_;
  51. // How much we reduce |penalty_counter_| every 10 ms.
  52. int penalty_decay_;
  53. // How old typing events we allow.
  54. int type_event_delay_;
  55. // Settable update period.
  56. // Number of 10 ms slots between each update of the detection status returned
  57. // by Process(). This inertia added to the algorithm is usually desirable and
  58. // provided so that consumers of the class don't have to implement that
  59. // themselves if they don't wish.
  60. // If set to 1, each call to Process() will return the detection status for
  61. // that 10 ms slot.
  62. // If set to N (where N > 1), the detection status returned from Process()
  63. // will remain the same until Process() has been called N times. Then, if none
  64. // of the last N calls to Process() has detected typing for each respective
  65. // 10 ms slot, Process() will return false. If at least one of the last N
  66. // calls has detected typing, Process() will return true. And that returned
  67. // status will then remain the same until the next N calls have been done.
  68. int report_detection_update_period_;
  69. };
  70. } // namespace webrtc
  71. #endif // #ifndef MODULES_AUDIO_PROCESSING_TYPING_DETECTION_H_