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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "content/browser/browser_main_loop.h" | 10 #include "content/browser/browser_main_loop.h" |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 | 504 |
505 // TODO(xians): Check if the OS has the device with |device_id_|, return | 505 // TODO(xians): Check if the OS has the device with |device_id_|, return |
506 // |SPEECH_AUDIO_ERROR_DETAILS_NO_MIC| if the target device does not exist. | 506 // |SPEECH_AUDIO_ERROR_DETAILS_NO_MIC| if the target device does not exist. |
507 if (!audio_manager->HasAudioInputDevices()) { | 507 if (!audio_manager->HasAudioInputDevices()) { |
508 return Abort(SpeechRecognitionError(SPEECH_RECOGNITION_ERROR_AUDIO, | 508 return Abort(SpeechRecognitionError(SPEECH_RECOGNITION_ERROR_AUDIO, |
509 SPEECH_AUDIO_ERROR_DETAILS_NO_MIC)); | 509 SPEECH_AUDIO_ERROR_DETAILS_NO_MIC)); |
510 } | 510 } |
511 | 511 |
512 int chunk_duration_ms = recognition_engine_->GetDesiredAudioChunkDurationMs(); | 512 int chunk_duration_ms = recognition_engine_->GetDesiredAudioChunkDurationMs(); |
513 | 513 |
514 // TODO(xians): use the correct input device here. | |
515 AudioParameters in_params = audio_manager->GetInputStreamParameters( | 514 AudioParameters in_params = audio_manager->GetInputStreamParameters( |
516 device_id_); | 515 device_id_); |
517 if (!in_params.IsValid() && !unit_test_is_active) { | 516 if (!in_params.IsValid() && !unit_test_is_active) { |
518 DLOG(ERROR) << "Invalid native audio input parameters"; | 517 DLOG(ERROR) << "Invalid native audio input parameters"; |
519 return Abort(SpeechRecognitionError(SPEECH_RECOGNITION_ERROR_AUDIO)); | 518 return Abort(SpeechRecognitionError(SPEECH_RECOGNITION_ERROR_AUDIO)); |
520 } | 519 } |
521 | 520 |
522 // Audio converter shall provide audio based on these parameters as output. | 521 // Audio converter shall provide audio based on these parameters as output. |
523 // Hard coded, WebSpeech specific parameters are utilized here. | 522 // Hard coded, WebSpeech specific parameters are utilized here. |
524 int frames_per_buffer = (kAudioSampleRate * chunk_duration_ms) / 1000; | 523 int frames_per_buffer = (kAudioSampleRate * chunk_duration_ms) / 1000; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 in_params.sample_rate(), | 556 in_params.sample_rate(), |
558 in_params.bits_per_sample(), | 557 in_params.bits_per_sample(), |
559 frames_per_buffer); | 558 frames_per_buffer); |
560 } | 559 } |
561 | 560 |
562 // Create an audio converter which converts data between native input format | 561 // Create an audio converter which converts data between native input format |
563 // and WebSpeech specific output format. | 562 // and WebSpeech specific output format. |
564 audio_converter_.reset( | 563 audio_converter_.reset( |
565 new OnDataConverter(input_parameters, output_parameters)); | 564 new OnDataConverter(input_parameters, output_parameters)); |
566 | 565 |
567 // TODO(xians): use the correct input device here. | |
568 audio_controller_ = AudioInputController::Create( | 566 audio_controller_ = AudioInputController::Create( |
569 audio_manager, this, input_parameters, device_id_); | 567 audio_manager, this, input_parameters, device_id_); |
570 | 568 |
571 if (!audio_controller_.get()) { | 569 if (!audio_controller_.get()) { |
572 return Abort(SpeechRecognitionError(SPEECH_RECOGNITION_ERROR_AUDIO)); | 570 return Abort(SpeechRecognitionError(SPEECH_RECOGNITION_ERROR_AUDIO)); |
573 } | 571 } |
574 | 572 |
575 // The endpointer needs to estimate the environment/background noise before | 573 // The endpointer needs to estimate the environment/background noise before |
576 // starting to treat the audio as user input. We wait in the state | 574 // starting to treat the audio as user input. We wait in the state |
577 // ESTIMATING_ENVIRONMENT until such interval has elapsed before switching | 575 // ESTIMATING_ENVIRONMENT until such interval has elapsed before switching |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 SpeechRecognizerImpl::FSMEventArgs::FSMEventArgs(FSMEvent event_value) | 810 SpeechRecognizerImpl::FSMEventArgs::FSMEventArgs(FSMEvent event_value) |
813 : event(event_value), | 811 : event(event_value), |
814 audio_data(NULL), | 812 audio_data(NULL), |
815 engine_error(SPEECH_RECOGNITION_ERROR_NONE) { | 813 engine_error(SPEECH_RECOGNITION_ERROR_NONE) { |
816 } | 814 } |
817 | 815 |
818 SpeechRecognizerImpl::FSMEventArgs::~FSMEventArgs() { | 816 SpeechRecognizerImpl::FSMEventArgs::~FSMEventArgs() { |
819 } | 817 } |
820 | 818 |
821 } // namespace content | 819 } // namespace content |
OLD | NEW |