summaryrefslogtreecommitdiffstats
path: root/content/browser/speech/speech_recognizer_unittest.cc
diff options
context:
space:
mode:
authorsatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-01 18:38:36 +0000
committersatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-01 18:38:36 +0000
commit3b283d6e8c6285efde6a1a34273a3bdb9061bd44 (patch)
tree9c221cc4d11dacf4f20e9c05287fde698d6721c6 /content/browser/speech/speech_recognizer_unittest.cc
parent229fa74de71e0771f734cc788063515da62f30b4 (diff)
downloadchromium_src-3b283d6e8c6285efde6a1a34273a3bdb9061bd44.zip
chromium_src-3b283d6e8c6285efde6a1a34273a3bdb9061bd44.tar.gz
chromium_src-3b283d6e8c6285efde6a1a34273a3bdb9061bd44.tar.bz2
Add a noise indicator to the speech bubble volume indicator.
The noise indicator is drawn as a light blue area at the beginning and if there was clipping that is denoted with a red area at the end of the meter. The noise level comes from the endpointer -> SpeechRecognizer -> SpeechInputBubbleController -> SpeechInputBubble hence a bunch of volume setting methods are updated with the new parameter. I have also added a new utility method to SpeechInputManager to invoke the platform provided microphone settings UI, this will be used in the next CL which contains windows, mac and linux specific UI changes. BUG=69886 TEST=manual, invoke speech input and check the bubble volume indicator to see background noise and clipping. Review URL: http://codereview.chromium.org/6597071 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76395 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/speech/speech_recognizer_unittest.cc')
-rw-r--r--content/browser/speech/speech_recognizer_unittest.cc19
1 files changed, 16 insertions, 3 deletions
diff --git a/content/browser/speech/speech_recognizer_unittest.cc b/content/browser/speech/speech_recognizer_unittest.cc
index 8365396..4b16259 100644
--- a/content/browser/speech/speech_recognizer_unittest.cc
+++ b/content/browser/speech/speech_recognizer_unittest.cc
@@ -62,8 +62,9 @@ class SpeechRecognizerTest : public SpeechRecognizerDelegate,
error_ = error;
}
- virtual void SetInputVolume(int caller_id, float volume) {
+ virtual void SetInputVolume(int caller_id, float volume, float noise_volume) {
volume_ = volume;
+ noise_volume_ = noise_volume;
}
// testing::Test methods.
@@ -83,6 +84,15 @@ class SpeechRecognizerTest : public SpeechRecognizerDelegate,
audio_packet_[i] = static_cast<uint8>(i);
}
+ void FillPacketWithNoise() {
+ int value = 0;
+ int factor = 175;
+ for (size_t i = 0; i < audio_packet_.size(); ++i) {
+ value += factor;
+ audio_packet_[i] = value % 100;
+ }
+ }
+
protected:
MessageLoopForIO message_loop_;
BrowserThread io_thread_;
@@ -95,6 +105,7 @@ class SpeechRecognizerTest : public SpeechRecognizerDelegate,
TestAudioInputControllerFactory audio_input_controller_factory_;
std::vector<uint8> audio_packet_;
float volume_;
+ float noise_volume_;
};
TEST_F(SpeechRecognizerTest, StopNoData) {
@@ -272,6 +283,7 @@ TEST_F(SpeechRecognizerTest, SetInputVolumeCallback) {
// Feed some samples to begin with for the endpointer to do noise estimation.
int num_packets = SpeechRecognizer::kEndpointerEstimationTimeMs /
SpeechRecognizer::kAudioPacketIntervalMs;
+ FillPacketWithNoise();
for (int i = 0; i < num_packets; ++i) {
controller->event_handler()->OnData(controller, &audio_packet_[0],
audio_packet_.size());
@@ -283,13 +295,14 @@ TEST_F(SpeechRecognizerTest, SetInputVolumeCallback) {
controller->event_handler()->OnData(controller, &audio_packet_[0],
audio_packet_.size());
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(0, volume_);
+ EXPECT_FLOAT_EQ(0.51877826f, volume_);
FillPacketWithTestWaveform();
controller->event_handler()->OnData(controller, &audio_packet_[0],
audio_packet_.size());
MessageLoop::current()->RunAllPending();
- EXPECT_FLOAT_EQ(0.9f, volume_);
+ EXPECT_FLOAT_EQ(0.81907868f, volume_);
+ EXPECT_FLOAT_EQ(0.52143687f, noise_volume_);
EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_);
EXPECT_FALSE(recording_complete_);