2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
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.
11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_TYPING_DETECTION_H_
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_TYPING_DETECTION_H_
14 #include "webrtc/modules/interface/module_common_types.h"
15 #include "webrtc/typedefs.h"
19 class TypingDetection {
22 virtual ~TypingDetection();
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);
29 // Gets the time in seconds since the last detection.
30 int TimeSinceLastDetectionInSeconds();
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,
36 int reporting_threshold,
39 int report_detection_update_period);
43 int time_since_last_typing_;
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_;
50 // The detection status to report. Updated every
51 // |report_detection_update_period_| call to Process().
52 bool detection_to_report_;
54 // What |detection_to_report_| should be set to next time it is updated.
55 bool new_detection_to_report_;
57 // Settable threshold values.
59 // Number of 10 ms slots accepted to count as a hit.
62 // Penalty added for a typing + activity coincide.
65 // Threshold for |penalty_counter_|.
66 int reporting_threshold_;
68 // How much we reduce |penalty_counter_| every 10 ms.
71 // How old typing events we allow.
72 int type_event_delay_;
74 // Settable update period.
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
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_;
93 #endif // #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_TYPING_DETECTION_H_