| 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_impl.h" | 5 #include "content/browser/speech/speech_recognizer_impl.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/browser/speech_recognizer.h" | |
| 16 #include "content/public/common/speech_recognition_error.h" | 15 #include "content/public/common/speech_recognition_error.h" |
| 17 #include "content/public/common/speech_recognition_result.h" | 16 #include "content/public/common/speech_recognition_result.h" |
| 18 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
| 19 | 18 |
| 20 using content::BrowserMainLoop; | 19 using content::BrowserMainLoop; |
| 21 using content::BrowserThread; | 20 using content::BrowserThread; |
| 22 using content::SpeechRecognitionError; | 21 using content::SpeechRecognitionError; |
| 23 using content::SpeechRecognitionEventListener; | 22 using content::SpeechRecognitionEventListener; |
| 24 using content::SpeechRecognitionResult; | 23 using content::SpeechRecognitionResult; |
| 25 using content::SpeechRecognizer; | |
| 26 using media::AudioInputController; | 24 using media::AudioInputController; |
| 27 using media::AudioManager; | 25 using media::AudioManager; |
| 28 using media::AudioParameters; | 26 using media::AudioParameters; |
| 29 | 27 |
| 30 namespace { | 28 namespace { |
| 31 | 29 |
| 32 // The following constants are related to the volume level indicator shown in | 30 // The following constants are related to the volume level indicator shown in |
| 33 // the UI for recorded audio. | 31 // the UI for recorded audio. |
| 34 // Multiplier used when new volume is greater than previous level. | 32 // Multiplier used when new volume is greater than previous level. |
| 35 const float kUpSmoothingFactor = 1.0f; | 33 const float kUpSmoothingFactor = 1.0f; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 59 } | 57 } |
| 60 } | 58 } |
| 61 return false; | 59 return false; |
| 62 } | 60 } |
| 63 | 61 |
| 64 void KeepAudioControllerRefcountedForDtor(scoped_refptr<AudioInputController>) { | 62 void KeepAudioControllerRefcountedForDtor(scoped_refptr<AudioInputController>) { |
| 65 } | 63 } |
| 66 | 64 |
| 67 } // namespace | 65 } // namespace |
| 68 | 66 |
| 69 // TODO(primiano) Create(...) is transitional (until we fix speech input | |
| 70 // extensions) and should be removed soon. The manager should be the only one | |
| 71 // knowing the existence of SpeechRecognizer(Impl), thus the only one in charge | |
| 72 // of instantiating it. | |
| 73 SpeechRecognizer* SpeechRecognizer::Create( | |
| 74 SpeechRecognitionEventListener* listener, | |
| 75 int session_id, | |
| 76 const std::string& language, | |
| 77 const std::string& grammar, | |
| 78 net::URLRequestContextGetter* context_getter, | |
| 79 bool filter_profanities, | |
| 80 const std::string& hardware_info, | |
| 81 const std::string& origin_url) { | |
| 82 speech::GoogleOneShotRemoteEngineConfig remote_engine_config; | |
| 83 remote_engine_config.language = language; | |
| 84 remote_engine_config.grammar = grammar; | |
| 85 remote_engine_config.audio_sample_rate = | |
| 86 speech::SpeechRecognizerImpl::kAudioSampleRate; | |
| 87 remote_engine_config.audio_num_bits_per_sample = | |
| 88 speech::SpeechRecognizerImpl::kNumBitsPerAudioSample; | |
| 89 remote_engine_config.filter_profanities = filter_profanities; | |
| 90 remote_engine_config.hardware_info = hardware_info; | |
| 91 remote_engine_config.origin_url = origin_url; | |
| 92 | |
| 93 // SpeechRecognizerImpl takes ownership of google_remote_engine. | |
| 94 speech::GoogleOneShotRemoteEngine* google_remote_engine = | |
| 95 new speech::GoogleOneShotRemoteEngine(context_getter); | |
| 96 google_remote_engine->SetConfig(remote_engine_config); | |
| 97 | |
| 98 return new speech::SpeechRecognizerImpl(listener, | |
| 99 session_id, | |
| 100 google_remote_engine); | |
| 101 } | |
| 102 | |
| 103 namespace speech { | 67 namespace speech { |
| 104 | 68 |
| 105 const int SpeechRecognizerImpl::kAudioSampleRate = 16000; | 69 const int SpeechRecognizerImpl::kAudioSampleRate = 16000; |
| 106 const ChannelLayout SpeechRecognizerImpl::kChannelLayout = CHANNEL_LAYOUT_MONO; | 70 const ChannelLayout SpeechRecognizerImpl::kChannelLayout = CHANNEL_LAYOUT_MONO; |
| 107 const int SpeechRecognizerImpl::kNumBitsPerAudioSample = 16; | 71 const int SpeechRecognizerImpl::kNumBitsPerAudioSample = 16; |
| 108 const int SpeechRecognizerImpl::kNoSpeechTimeoutMs = 8000; | 72 const int SpeechRecognizerImpl::kNoSpeechTimeoutMs = 8000; |
| 109 const int SpeechRecognizerImpl::kEndpointerEstimationTimeMs = 300; | 73 const int SpeechRecognizerImpl::kEndpointerEstimationTimeMs = 300; |
| 110 | 74 |
| 111 COMPILE_ASSERT(SpeechRecognizerImpl::kNumBitsPerAudioSample % 8 == 0, | 75 COMPILE_ASSERT(SpeechRecognizerImpl::kNumBitsPerAudioSample % 8 == 0, |
| 112 kNumBitsPerAudioSample_must_be_a_multiple_of_8); | 76 kNumBitsPerAudioSample_must_be_a_multiple_of_8); |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 : event(event_value), | 606 : event(event_value), |
| 643 audio_error_code(0), | 607 audio_error_code(0), |
| 644 audio_data(NULL), | 608 audio_data(NULL), |
| 645 engine_error(content::SPEECH_RECOGNITION_ERROR_NONE) { | 609 engine_error(content::SPEECH_RECOGNITION_ERROR_NONE) { |
| 646 } | 610 } |
| 647 | 611 |
| 648 SpeechRecognizerImpl::FSMEventArgs::~FSMEventArgs() { | 612 SpeechRecognizerImpl::FSMEventArgs::~FSMEventArgs() { |
| 649 } | 613 } |
| 650 | 614 |
| 651 } // namespace speech | 615 } // namespace speech |
| OLD | NEW |