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