summaryrefslogtreecommitdiffstats
path: root/content/browser/speech/endpointer
diff options
context:
space:
mode:
Diffstat (limited to 'content/browser/speech/endpointer')
-rw-r--r--content/browser/speech/endpointer/endpointer.h3
-rw-r--r--content/browser/speech/endpointer/energy_endpointer.cc18
-rw-r--r--content/browser/speech/endpointer/energy_endpointer.h3
3 files changed, 19 insertions, 5 deletions
diff --git a/content/browser/speech/endpointer/endpointer.h b/content/browser/speech/endpointer/endpointer.h
index be4bd65..c8cf80a 100644
--- a/content/browser/speech/endpointer/endpointer.h
+++ b/content/browser/speech/endpointer/endpointer.h
@@ -96,6 +96,9 @@ class Endpointer {
return speech_input_complete_;
}
+ // RMS background noise level in dB.
+ float NoiseLevelDb() const { return energy_endpointer_.GetNoiseLevelDb(); }
+
private:
// Reset internal states. Helper method common to initial input utterance
// and following input utternaces.
diff --git a/content/browser/speech/endpointer/energy_endpointer.cc b/content/browser/speech/endpointer/energy_endpointer.cc
index c806aed..edf3edd 100644
--- a/content/browser/speech/endpointer/energy_endpointer.cc
+++ b/content/browser/speech/endpointer/energy_endpointer.cc
@@ -33,6 +33,13 @@ int64 Secs2Usecs(float seconds) {
return static_cast<int64>(0.5 + (1.0e6 * seconds));
}
+float GetDecibel(float value) {
+ const float kVerySmallValue = 1.0e-100f;
+ if (value < kVerySmallValue)
+ value = kVerySmallValue;
+ return 20 * log10(value);
+}
+
} // namespace
namespace speech_input {
@@ -326,11 +333,12 @@ void EnergyEndpointer::ProcessAudioFrame(int64 time_us,
UpdateLevels(rms);
++frame_counter_;
- if (rms_out) {
- *rms_out = -120.0;
- if ((noise_level_ > 0.0) && ((rms / noise_level_ ) > 0.000001))
- *rms_out = static_cast<float>(20.0 * log10(rms / noise_level_));
- }
+ if (rms_out)
+ *rms_out = GetDecibel(rms);
+}
+
+float EnergyEndpointer::GetNoiseLevelDb() const {
+ return GetDecibel(noise_level_);
}
void EnergyEndpointer::UpdateLevels(float rms) {
diff --git a/content/browser/speech/endpointer/energy_endpointer.h b/content/browser/speech/endpointer/energy_endpointer.h
index b10d8b7..77ccc55 100644
--- a/content/browser/speech/endpointer/energy_endpointer.h
+++ b/content/browser/speech/endpointer/energy_endpointer.h
@@ -91,6 +91,9 @@ class EnergyEndpointer {
return estimating_environment_;
}
+ // Returns estimated noise level in dB.
+ float GetNoiseLevelDb() const;
+
private:
class HistoryRing;