OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/speech/speech_recognizer.h" | 5 #include "chrome/browser/speech/speech_recognizer.h" |
6 | 6 |
7 #include "base/ref_counted.h" | 7 #include "base/ref_counted.h" |
8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "chrome/browser/browser_thread.h" | 10 #include "chrome/browser/browser_thread.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 VLOG(1) << "SpeechRecognizer stopping record."; | 122 VLOG(1) << "SpeechRecognizer stopping record."; |
123 audio_controller_->Close(); | 123 audio_controller_->Close(); |
124 audio_controller_ = NULL; // Releases the ref ptr. | 124 audio_controller_ = NULL; // Releases the ref ptr. |
125 encoder_->Flush(); | 125 encoder_->Flush(); |
126 | 126 |
127 delegate_->DidCompleteRecording(caller_id_); | 127 delegate_->DidCompleteRecording(caller_id_); |
128 | 128 |
129 // Since the http request takes a single string as POST data, allocate | 129 // Since the http request takes a single string as POST data, allocate |
130 // one and copy over bytes from the audio buffers to the string. | 130 // one and copy over bytes from the audio buffers to the string. |
131 // And If we haven't got any audio yet end the recognition sequence here. | 131 // And If we haven't got any audio yet end the recognition sequence here. |
| 132 string mime_type = encoder_->mime_type(); |
132 string data; | 133 string data; |
133 if (!encoder_->GetEncodedData(&data)) { | 134 encoder_->GetEncodedData(&data); |
| 135 encoder_.reset(); |
| 136 |
| 137 if (data.empty()) { |
134 // Guard against the delegate freeing us until we finish our job. | 138 // Guard against the delegate freeing us until we finish our job. |
135 scoped_refptr<SpeechRecognizer> me(this); | 139 scoped_refptr<SpeechRecognizer> me(this); |
136 delegate_->DidCompleteRecognition(caller_id_); | 140 delegate_->DidCompleteRecognition(caller_id_); |
137 } else { | 141 } else { |
138 DCHECK(!request_.get()); | 142 DCHECK(!request_.get()); |
139 request_.reset(new SpeechRecognitionRequest( | 143 request_.reset(new SpeechRecognitionRequest( |
140 Profile::GetDefaultRequestContext(), this)); | 144 Profile::GetDefaultRequestContext(), this)); |
141 request_->Send(language_, grammar_, hardware_info_, origin_url_, | 145 request_->Send(language_, grammar_, hardware_info_, origin_url_, |
142 encoder_->mime_type(), data); | 146 mime_type, data); |
143 } | 147 } |
144 encoder_.reset(); | |
145 } | 148 } |
146 | 149 |
147 void SpeechRecognizer::ReleaseAudioBuffers() { | 150 void SpeechRecognizer::ReleaseAudioBuffers() { |
148 } | 151 } |
149 | 152 |
150 // Invoked in the audio thread. | 153 // Invoked in the audio thread. |
151 void SpeechRecognizer::OnError(AudioInputController* controller, | 154 void SpeechRecognizer::OnError(AudioInputController* controller, |
152 int error_code) { | 155 int error_code) { |
153 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 156 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
154 NewRunnableMethod(this, | 157 NewRunnableMethod(this, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 | 255 |
253 void SpeechRecognizer::InformErrorAndCancelRecognition(ErrorCode error) { | 256 void SpeechRecognizer::InformErrorAndCancelRecognition(ErrorCode error) { |
254 CancelRecognition(); | 257 CancelRecognition(); |
255 | 258 |
256 // Guard against the delegate freeing us until we finish our job. | 259 // Guard against the delegate freeing us until we finish our job. |
257 scoped_refptr<SpeechRecognizer> me(this); | 260 scoped_refptr<SpeechRecognizer> me(this); |
258 delegate_->OnRecognizerError(caller_id_, error); | 261 delegate_->OnRecognizerError(caller_id_, error); |
259 } | 262 } |
260 | 263 |
261 } // namespace speech_input | 264 } // namespace speech_input |
OLD | NEW |