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

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

Issue 9568002: Renamed speech input implementation from to speech_recognition_*. The namespace has been renamed fr… (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebased from master. Created 8 years, 9 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
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 #ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_ 5 #ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_
6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_ 6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_
7 7
8 #include <list> 8 #include <list>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "content/browser/speech/audio_encoder.h" 13 #include "content/browser/speech/audio_encoder.h"
14 #include "content/browser/speech/endpointer/endpointer.h" 14 #include "content/browser/speech/endpointer/endpointer.h"
15 #include "content/browser/speech/speech_recognition_request.h" 15 #include "content/browser/speech/speech_recognition_request.h"
16 #include "content/public/browser/speech_recognizer.h" 16 #include "content/public/browser/speech_recognizer.h"
17 #include "content/public/common/speech_input_result.h" 17 #include "content/public/common/speech_recognition_result.h"
18 #include "media/audio/audio_input_controller.h" 18 #include "media/audio/audio_input_controller.h"
19 19
20 class AudioManager; 20 class AudioManager;
21 21
22 namespace speech_input { 22 namespace speech {
23 23
24 // Records audio, sends recorded audio to server and translates server response 24 // Records audio, sends recorded audio to server and translates server response
25 // to recognition result. 25 // to recognition result.
26 class CONTENT_EXPORT SpeechRecognizerImpl 26 class CONTENT_EXPORT SpeechRecognizerImpl
27 : NON_EXPORTED_BASE(public content::SpeechRecognizer), 27 : NON_EXPORTED_BASE(public content::SpeechRecognizer),
28 public media::AudioInputController::EventHandler, 28 public media::AudioInputController::EventHandler,
29 public SpeechRecognitionRequestDelegate { 29 public SpeechRecognitionRequestDelegate {
30 public: 30 public:
31 SpeechRecognizerImpl(content::SpeechRecognizerDelegate* delegate, 31 SpeechRecognizerImpl(content::SpeechRecognizerDelegate* delegate,
32 int caller_id, 32 int caller_id,
33 const std::string& language, 33 const std::string& language,
34 const std::string& grammar, 34 const std::string& grammar,
35 net::URLRequestContextGetter* context_getter, 35 net::URLRequestContextGetter* context_getter,
36 bool filter_profanities, 36 bool filter_profanities,
37 const std::string& hardware_info, 37 const std::string& hardware_info,
38 const std::string& origin_url); 38 const std::string& origin_url);
39 39
40 virtual ~SpeechRecognizerImpl(); 40 virtual ~SpeechRecognizerImpl();
41 41
42 // SpeechRecognizer implementation: 42 // SpeechRecognizer implementation:
43 virtual bool StartRecording() OVERRIDE; 43 virtual bool StartRecording() OVERRIDE;
44 virtual void CancelRecognition() OVERRIDE; 44 virtual void CancelRecognition() OVERRIDE;
45 45
46 // Stops recording audio and starts recognition. 46 // Stops recording audio and starts recognition.
47 void StopRecording(); 47 void StopRecording();
48 48
49 // AudioInputController::EventHandler methods. 49 // AudioInputController::EventHandler methods.
50 virtual void OnCreated(media::AudioInputController* controller) OVERRIDE { } 50 virtual void OnCreated(media::AudioInputController* controller) OVERRIDE {}
51 virtual void OnRecording(media::AudioInputController* controller) OVERRIDE { } 51 virtual void OnRecording(media::AudioInputController* controller) OVERRIDE {}
52 virtual void OnError(media::AudioInputController* controller, 52 virtual void OnError(media::AudioInputController* controller,
53 int error_code) OVERRIDE; 53 int error_code) OVERRIDE;
54 virtual void OnData(media::AudioInputController* controller, 54 virtual void OnData(media::AudioInputController* controller,
55 const uint8* data, 55 const uint8* data,
56 uint32 size) OVERRIDE; 56 uint32 size) OVERRIDE;
57 57
58 // SpeechRecognitionRequest::Delegate methods. 58 // SpeechRecognitionRequest::Delegate methods.
59 virtual void SetRecognitionResult( 59 virtual void SetRecognitionResult(
60 const content::SpeechInputResult& result) OVERRIDE; 60 const content::SpeechRecognitionResult& result) OVERRIDE;
61 61
62 static const int kAudioSampleRate; 62 static const int kAudioSampleRate;
63 static const int kAudioPacketIntervalMs; // Duration of each audio packet. 63 static const int kAudioPacketIntervalMs; // Duration of each audio packet.
64 static const ChannelLayout kChannelLayout; 64 static const ChannelLayout kChannelLayout;
65 static const int kNumBitsPerAudioSample; 65 static const int kNumBitsPerAudioSample;
66 static const int kNoSpeechTimeoutSec; 66 static const int kNoSpeechTimeoutSec;
67 static const int kEndpointerEstimationTimeMs; 67 static const int kEndpointerEstimationTimeMs;
68 68
69 private: 69 private:
70 friend class SpeechRecognizerTest; 70 friend class SpeechRecognizerTest;
71 71
72 void InformErrorAndCancelRecognition(content::SpeechInputError error); 72 void InformErrorAndCancelRecognition(
73 content::SpeechRecognitionErrorCode error);
73 void SendRecordedAudioToServer(); 74 void SendRecordedAudioToServer();
74 75
75 void HandleOnError(int error_code); // Handles OnError in the IO thread. 76 void HandleOnError(int error_code); // Handles OnError in the IO thread.
76 77
77 // Handles OnData in the IO thread. Takes ownership of |data|. 78 // Handles OnData in the IO thread. Takes ownership of |data|.
78 void HandleOnData(std::string* data); 79 void HandleOnData(std::string* data);
79 80
80 // Helper method which closes the audio controller and blocks until done. 81 // Helper method which closes the audio controller and blocks until done.
81 void CloseAudioControllerSynchronously(); 82 void CloseAudioControllerSynchronously();
82 83
(...skipping 13 matching lines...) Expand all
96 AudioEncoder::Codec codec_; 97 AudioEncoder::Codec codec_;
97 scoped_ptr<AudioEncoder> encoder_; 98 scoped_ptr<AudioEncoder> encoder_;
98 Endpointer endpointer_; 99 Endpointer endpointer_;
99 int num_samples_recorded_; 100 int num_samples_recorded_;
100 float audio_level_; 101 float audio_level_;
101 AudioManager* audio_manager_; 102 AudioManager* audio_manager_;
102 103
103 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizerImpl); 104 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizerImpl);
104 }; 105 };
105 106
106 } // namespace speech_input 107 } // namespace speech
107 108
108 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_ 109 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/speech/speech_recognition_request_unittest.cc ('k') | content/browser/speech/speech_recognizer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698