Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1276)

Side by Side Diff: content/browser/speech/speech_recognizer_impl.cc

Issue 10440011: SpeechInputExtensionManager now interface (exclusively) with SpeechRecognitionManagerDelegate (Spee… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Satish review Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/speech/speech_recognizer_impl.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_grammar.h" 16 #include "content/public/common/speech_recognition_grammar.h"
18 #include "content/public/common/speech_recognition_result.h" 17 #include "content/public/common/speech_recognition_result.h"
19 #include "net/url_request/url_request_context_getter.h" 18 #include "net/url_request/url_request_context_getter.h"
20 19
21 using content::BrowserMainLoop; 20 using content::BrowserMainLoop;
22 using content::BrowserThread; 21 using content::BrowserThread;
23 using content::SpeechRecognitionError; 22 using content::SpeechRecognitionError;
24 using content::SpeechRecognitionEventListener; 23 using content::SpeechRecognitionEventListener;
25 using content::SpeechRecognitionGrammar; 24 using content::SpeechRecognitionGrammar;
26 using content::SpeechRecognitionResult; 25 using content::SpeechRecognitionResult;
27 using content::SpeechRecognizer;
28 using media::AudioInputController; 26 using media::AudioInputController;
29 using media::AudioManager; 27 using media::AudioManager;
30 using media::AudioParameters; 28 using media::AudioParameters;
31 29
32 namespace { 30 namespace {
33 31
34 // The following constants are related to the volume level indicator shown in 32 // The following constants are related to the volume level indicator shown in
35 // the UI for recorded audio. 33 // the UI for recorded audio.
36 // Multiplier used when new volume is greater than previous level. 34 // Multiplier used when new volume is greater than previous level.
37 const float kUpSmoothingFactor = 1.0f; 35 const float kUpSmoothingFactor = 1.0f;
(...skipping 23 matching lines...) Expand all
61 } 59 }
62 } 60 }
63 return false; 61 return false;
64 } 62 }
65 63
66 void KeepAudioControllerRefcountedForDtor(scoped_refptr<AudioInputController>) { 64 void KeepAudioControllerRefcountedForDtor(scoped_refptr<AudioInputController>) {
67 } 65 }
68 66
69 } // namespace 67 } // namespace
70 68
71 // TODO(primiano) Create(...) is transitional (until we fix speech input
72 // extensions) and should be removed soon. The manager should be the only one
73 // knowing the existence of SpeechRecognizer(Impl), thus the only one in charge
74 // of instantiating it.
75 SpeechRecognizer* SpeechRecognizer::Create(
76 SpeechRecognitionEventListener* listener,
77 int session_id,
78 const std::string& language,
79 const std::string& grammar,
80 net::URLRequestContextGetter* context_getter,
81 bool filter_profanities,
82 const std::string& hardware_info,
83 const std::string& origin_url) {
84 speech::SpeechRecognitionEngineConfig remote_engine_config;
85 remote_engine_config.language = language;
86 if (!grammar.empty())
87 remote_engine_config.grammars.push_back(SpeechRecognitionGrammar(grammar));
88 remote_engine_config.audio_sample_rate =
89 speech::SpeechRecognizerImpl::kAudioSampleRate;
90 remote_engine_config.audio_num_bits_per_sample =
91 speech::SpeechRecognizerImpl::kNumBitsPerAudioSample;
92 remote_engine_config.filter_profanities = filter_profanities;
93 remote_engine_config.hardware_info = hardware_info;
94 remote_engine_config.origin_url = origin_url;
95
96 // SpeechRecognizerImpl takes ownership of google_remote_engine.
97 speech::GoogleOneShotRemoteEngine* google_remote_engine =
98 new speech::GoogleOneShotRemoteEngine(context_getter);
99 google_remote_engine->SetConfig(remote_engine_config);
100
101 return new speech::SpeechRecognizerImpl(listener,
102 session_id,
103 google_remote_engine);
104 }
105
106 namespace speech { 69 namespace speech {
107 70
108 const int SpeechRecognizerImpl::kAudioSampleRate = 16000; 71 const int SpeechRecognizerImpl::kAudioSampleRate = 16000;
109 const ChannelLayout SpeechRecognizerImpl::kChannelLayout = CHANNEL_LAYOUT_MONO; 72 const ChannelLayout SpeechRecognizerImpl::kChannelLayout = CHANNEL_LAYOUT_MONO;
110 const int SpeechRecognizerImpl::kNumBitsPerAudioSample = 16; 73 const int SpeechRecognizerImpl::kNumBitsPerAudioSample = 16;
111 const int SpeechRecognizerImpl::kNoSpeechTimeoutMs = 8000; 74 const int SpeechRecognizerImpl::kNoSpeechTimeoutMs = 8000;
112 const int SpeechRecognizerImpl::kEndpointerEstimationTimeMs = 300; 75 const int SpeechRecognizerImpl::kEndpointerEstimationTimeMs = 300;
113 76
114 COMPILE_ASSERT(SpeechRecognizerImpl::kNumBitsPerAudioSample % 8 == 0, 77 COMPILE_ASSERT(SpeechRecognizerImpl::kNumBitsPerAudioSample % 8 == 0,
115 kNumBitsPerAudioSample_must_be_a_multiple_of_8); 78 kNumBitsPerAudioSample_must_be_a_multiple_of_8);
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 : event(event_value), 608 : event(event_value),
646 audio_error_code(0), 609 audio_error_code(0),
647 audio_data(NULL), 610 audio_data(NULL),
648 engine_error(content::SPEECH_RECOGNITION_ERROR_NONE) { 611 engine_error(content::SPEECH_RECOGNITION_ERROR_NONE) {
649 } 612 }
650 613
651 SpeechRecognizerImpl::FSMEventArgs::~FSMEventArgs() { 614 SpeechRecognizerImpl::FSMEventArgs::~FSMEventArgs() {
652 } 615 }
653 616
654 } // namespace speech 617 } // namespace speech
OLDNEW
« no previous file with comments | « content/browser/speech/speech_recognizer_impl.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698