| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 269 |
| 270 // Invoked in the audio thread. | 270 // Invoked in the audio thread. |
| 271 void SpeechRecognizerImpl::OnError(AudioInputController* controller, | 271 void SpeechRecognizerImpl::OnError(AudioInputController* controller, |
| 272 media::AudioInputController::ErrorCode error_code) { | 272 media::AudioInputController::ErrorCode error_code) { |
| 273 FSMEventArgs event_args(EVENT_AUDIO_ERROR); | 273 FSMEventArgs event_args(EVENT_AUDIO_ERROR); |
| 274 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 274 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 275 base::Bind(&SpeechRecognizerImpl::DispatchEvent, | 275 base::Bind(&SpeechRecognizerImpl::DispatchEvent, |
| 276 this, event_args)); | 276 this, event_args)); |
| 277 } | 277 } |
| 278 | 278 |
| 279 void SpeechRecognizerImpl::OnData(AudioInputController* controller, | 279 void SpeechRecognizerImpl::Write(const AudioBus* data, |
| 280 const AudioBus* data) { | 280 double volume, |
| 281 bool key_pressed, |
| 282 uint32_t hardware_delay_bytes) { |
| 281 // Convert audio from native format to fixed format used by WebSpeech. | 283 // Convert audio from native format to fixed format used by WebSpeech. |
| 282 FSMEventArgs event_args(EVENT_AUDIO_DATA); | 284 FSMEventArgs event_args(EVENT_AUDIO_DATA); |
| 283 event_args.audio_data = audio_converter_->Convert(data); | 285 event_args.audio_data = audio_converter_->Convert(data); |
| 284 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 286 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 285 base::Bind(&SpeechRecognizerImpl::DispatchEvent, | 287 base::Bind(&SpeechRecognizerImpl::DispatchEvent, |
| 286 this, event_args)); | 288 this, event_args)); |
| 287 // See http://crbug.com/506051 regarding why one extra convert call can | 289 // See http://crbug.com/506051 regarding why one extra convert call can |
| 288 // sometimes be required. It should be a rare case. | 290 // sometimes be required. It should be a rare case. |
| 289 if (!audio_converter_->data_was_converted()) { | 291 if (!audio_converter_->data_was_converted()) { |
| 290 event_args.audio_data = audio_converter_->Convert(data); | 292 event_args.audio_data = audio_converter_->Convert(data); |
| 291 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 293 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 292 base::Bind(&SpeechRecognizerImpl::DispatchEvent, | 294 base::Bind(&SpeechRecognizerImpl::DispatchEvent, |
| 293 this, event_args)); | 295 this, event_args)); |
| 294 } | 296 } |
| 295 // Something is seriously wrong here and we are most likely missing some | 297 // Something is seriously wrong here and we are most likely missing some |
| 296 // audio segments. | 298 // audio segments. |
| 297 CHECK(audio_converter_->data_was_converted()); | 299 CHECK(audio_converter_->data_was_converted()); |
| 298 } | 300 } |
| 299 | 301 |
| 302 void SpeechRecognizerImpl::Close() {} |
| 303 |
| 300 void SpeechRecognizerImpl::OnAudioClosed(AudioInputController*) {} | 304 void SpeechRecognizerImpl::OnAudioClosed(AudioInputController*) {} |
| 301 | 305 |
| 302 void SpeechRecognizerImpl::OnSpeechRecognitionEngineResults( | 306 void SpeechRecognizerImpl::OnSpeechRecognitionEngineResults( |
| 303 const SpeechRecognitionResults& results) { | 307 const SpeechRecognitionResults& results) { |
| 304 FSMEventArgs event_args(EVENT_ENGINE_RESULT); | 308 FSMEventArgs event_args(EVENT_ENGINE_RESULT); |
| 305 event_args.engine_results = results; | 309 event_args.engine_results = results; |
| 306 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 310 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 307 base::Bind(&SpeechRecognizerImpl::DispatchEvent, | 311 base::Bind(&SpeechRecognizerImpl::DispatchEvent, |
| 308 this, event_args)); | 312 this, event_args)); |
| 309 } | 313 } |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 DVLOG(1) << "SRI::input_parameters: " | 582 DVLOG(1) << "SRI::input_parameters: " |
| 579 << input_parameters.AsHumanReadableString(); | 583 << input_parameters.AsHumanReadableString(); |
| 580 } | 584 } |
| 581 | 585 |
| 582 // Create an audio converter which converts data between native input format | 586 // Create an audio converter which converts data between native input format |
| 583 // and WebSpeech specific output format. | 587 // and WebSpeech specific output format. |
| 584 audio_converter_.reset( | 588 audio_converter_.reset( |
| 585 new OnDataConverter(input_parameters, output_parameters)); | 589 new OnDataConverter(input_parameters, output_parameters)); |
| 586 | 590 |
| 587 audio_controller_ = AudioInputController::Create( | 591 audio_controller_ = AudioInputController::Create( |
| 588 audio_manager, this, input_parameters, device_id_, NULL); | 592 audio_manager, this, this, input_parameters, device_id_, NULL); |
| 589 | 593 |
| 590 if (!audio_controller_.get()) { | 594 if (!audio_controller_.get()) { |
| 591 return Abort( | 595 return Abort( |
| 592 SpeechRecognitionError(SPEECH_RECOGNITION_ERROR_AUDIO_CAPTURE)); | 596 SpeechRecognitionError(SPEECH_RECOGNITION_ERROR_AUDIO_CAPTURE)); |
| 593 } | 597 } |
| 594 | 598 |
| 595 audio_log_->OnCreated(0, input_parameters, device_id_); | 599 audio_log_->OnCreated(0, input_parameters, device_id_); |
| 596 | 600 |
| 597 // The endpointer needs to estimate the environment/background noise before | 601 // The endpointer needs to estimate the environment/background noise before |
| 598 // starting to treat the audio as user input. We wait in the state | 602 // starting to treat the audio as user input. We wait in the state |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 engine_error(SPEECH_RECOGNITION_ERROR_NONE) { | 840 engine_error(SPEECH_RECOGNITION_ERROR_NONE) { |
| 837 } | 841 } |
| 838 | 842 |
| 839 SpeechRecognizerImpl::FSMEventArgs::FSMEventArgs(const FSMEventArgs& other) = | 843 SpeechRecognizerImpl::FSMEventArgs::FSMEventArgs(const FSMEventArgs& other) = |
| 840 default; | 844 default; |
| 841 | 845 |
| 842 SpeechRecognizerImpl::FSMEventArgs::~FSMEventArgs() { | 846 SpeechRecognizerImpl::FSMEventArgs::~FSMEventArgs() { |
| 843 } | 847 } |
| 844 | 848 |
| 845 } // namespace content | 849 } // namespace content |
| OLD | NEW |