| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/speech/speech_recognizer.h" | 5 #include "content/browser/speech/speech_recognizer.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "content/browser/browser_main_loop.h" | 10 #include "content/browser/browser_main_loop.h" |
| 11 #include "content/browser/speech/audio_buffer.h" | 11 #include "content/browser/speech/audio_buffer.h" |
| 12 #include "content/browser/speech/google_one_shot_remote_engine.h" | 12 #include "content/browser/speech/google_one_shot_remote_engine.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/speech_recognition_event_listener.h" | 14 #include "content/public/browser/speech_recognition_event_listener.h" |
| 15 #include "content/public/common/speech_recognition_error.h" | 15 #include "content/public/common/speech_recognition_error.h" |
| 16 #include "content/public/common/speech_recognition_grammar.h" | 16 #include "content/public/common/speech_recognition_grammar.h" |
| 17 #include "content/public/common/speech_recognition_result.h" | 17 #include "content/public/common/speech_recognition_result.h" |
| 18 #include "net/url_request/url_request_context_getter.h" | 18 #include "net/url_request/url_request_context_getter.h" |
| 19 | 19 |
| 20 using content::BrowserMainLoop; | 20 using content::BrowserMainLoop; |
| 21 using content::BrowserThread; | 21 using content::BrowserThread; |
| 22 using content::SpeechRecognitionError; | 22 using content::SpeechRecognitionError; |
| 23 using content::SpeechRecognitionEventListener; | 23 using content::SpeechRecognitionEventListener; |
| 24 using content::SpeechRecognitionGrammar; | 24 using content::SpeechRecognitionGrammar; |
| 25 using content::SpeechRecognitionResult; | 25 using content::SpeechRecognitionResult; |
| 26 using media::AudioInputController; | 26 using media::AudioInputController; |
| 27 using media::AudioManager; | 27 using media::AudioManager; |
| 28 using media::AudioParameters; | 28 using media::AudioParameters; |
| 29 using media::ChannelLayout; |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 // The following constants are related to the volume level indicator shown in | 33 // The following constants are related to the volume level indicator shown in |
| 33 // the UI for recorded audio. | 34 // the UI for recorded audio. |
| 34 // Multiplier used when new volume is greater than previous level. | 35 // Multiplier used when new volume is greater than previous level. |
| 35 const float kUpSmoothingFactor = 1.0f; | 36 const float kUpSmoothingFactor = 1.0f; |
| 36 // Multiplier used when new volume is lesser than previous level. | 37 // Multiplier used when new volume is lesser than previous level. |
| 37 const float kDownSmoothingFactor = 0.7f; | 38 const float kDownSmoothingFactor = 0.7f; |
| 38 // RMS dB value of a maximum (unclipped) sine wave for int16 samples. | 39 // RMS dB value of a maximum (unclipped) sine wave for int16 samples. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 62 } | 63 } |
| 63 | 64 |
| 64 void KeepAudioControllerRefcountedForDtor(scoped_refptr<AudioInputController>) { | 65 void KeepAudioControllerRefcountedForDtor(scoped_refptr<AudioInputController>) { |
| 65 } | 66 } |
| 66 | 67 |
| 67 } // namespace | 68 } // namespace |
| 68 | 69 |
| 69 namespace speech { | 70 namespace speech { |
| 70 | 71 |
| 71 const int SpeechRecognizer::kAudioSampleRate = 16000; | 72 const int SpeechRecognizer::kAudioSampleRate = 16000; |
| 72 const ChannelLayout SpeechRecognizer::kChannelLayout = CHANNEL_LAYOUT_MONO; | 73 const ChannelLayout SpeechRecognizer::kChannelLayout = |
| 74 media::CHANNEL_LAYOUT_MONO; |
| 73 const int SpeechRecognizer::kNumBitsPerAudioSample = 16; | 75 const int SpeechRecognizer::kNumBitsPerAudioSample = 16; |
| 74 const int SpeechRecognizer::kNoSpeechTimeoutMs = 8000; | 76 const int SpeechRecognizer::kNoSpeechTimeoutMs = 8000; |
| 75 const int SpeechRecognizer::kEndpointerEstimationTimeMs = 300; | 77 const int SpeechRecognizer::kEndpointerEstimationTimeMs = 300; |
| 76 media::AudioManager* SpeechRecognizer::audio_manager_for_tests_ = NULL; | 78 media::AudioManager* SpeechRecognizer::audio_manager_for_tests_ = NULL; |
| 77 | 79 |
| 78 COMPILE_ASSERT(SpeechRecognizer::kNumBitsPerAudioSample % 8 == 0, | 80 COMPILE_ASSERT(SpeechRecognizer::kNumBitsPerAudioSample % 8 == 0, |
| 79 kNumBitsPerAudioSample_must_be_a_multiple_of_8); | 81 kNumBitsPerAudioSample_must_be_a_multiple_of_8); |
| 80 | 82 |
| 81 SpeechRecognizer::SpeechRecognizer( | 83 SpeechRecognizer::SpeechRecognizer( |
| 82 SpeechRecognitionEventListener* listener, | 84 SpeechRecognitionEventListener* listener, |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 : event(event_value), | 660 : event(event_value), |
| 659 audio_error_code(0), | 661 audio_error_code(0), |
| 660 audio_data(NULL), | 662 audio_data(NULL), |
| 661 engine_error(content::SPEECH_RECOGNITION_ERROR_NONE) { | 663 engine_error(content::SPEECH_RECOGNITION_ERROR_NONE) { |
| 662 } | 664 } |
| 663 | 665 |
| 664 SpeechRecognizer::FSMEventArgs::~FSMEventArgs() { | 666 SpeechRecognizer::FSMEventArgs::~FSMEventArgs() { |
| 665 } | 667 } |
| 666 | 668 |
| 667 } // namespace speech | 669 } // namespace speech |
| OLD | NEW |