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