OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_H_ | 5 #ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ |
6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ | 6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "content/browser/speech/audio_encoder.h" | 14 #include "content/browser/speech/audio_encoder.h" |
15 #include "content/browser/speech/endpointer/endpointer.h" | 15 #include "content/browser/speech/endpointer/endpointer.h" |
16 #include "content/browser/speech/speech_recognition_request.h" | 16 #include "content/browser/speech/speech_recognition_request.h" |
| 17 #include "content/common/content_export.h" |
17 #include "media/audio/audio_input_controller.h" | 18 #include "media/audio/audio_input_controller.h" |
18 | 19 |
19 namespace speech_input { | 20 namespace speech_input { |
20 | 21 |
21 // Records audio, sends recorded audio to server and translates server response | 22 // Records audio, sends recorded audio to server and translates server response |
22 // to recognition result. | 23 // to recognition result. |
23 class SpeechRecognizer | 24 class SpeechRecognizer |
24 : public base::RefCountedThreadSafe<SpeechRecognizer>, | 25 : public base::RefCountedThreadSafe<SpeechRecognizer>, |
25 public media::AudioInputController::EventHandler, | 26 public media::AudioInputController::EventHandler, |
26 public SpeechRecognitionRequestDelegate { | 27 public SpeechRecognitionRequestDelegate { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // Informs of a change in the captured audio level, useful if displaying | 72 // Informs of a change in the captured audio level, useful if displaying |
72 // a microphone volume indicator while recording. | 73 // a microphone volume indicator while recording. |
73 // The value of |volume| and |noise_volume| is in the [0.0, 1.0] range. | 74 // The value of |volume| and |noise_volume| is in the [0.0, 1.0] range. |
74 virtual void SetInputVolume(int caller_id, float volume, | 75 virtual void SetInputVolume(int caller_id, float volume, |
75 float noise_volume) = 0; | 76 float noise_volume) = 0; |
76 | 77 |
77 protected: | 78 protected: |
78 virtual ~Delegate() {} | 79 virtual ~Delegate() {} |
79 }; | 80 }; |
80 | 81 |
81 SpeechRecognizer(Delegate* delegate, | 82 CONTENT_EXPORT SpeechRecognizer(Delegate* delegate, |
82 int caller_id, | 83 int caller_id, |
83 const std::string& language, | 84 const std::string& language, |
84 const std::string& grammar, | 85 const std::string& grammar, |
85 bool censor_results, | 86 bool censor_results, |
86 const std::string& hardware_info, | 87 const std::string& hardware_info, |
87 const std::string& origin_url); | 88 const std::string& origin_url); |
88 virtual ~SpeechRecognizer(); | 89 virtual ~SpeechRecognizer(); |
89 | 90 |
90 // Starts audio recording and does recognition after recording ends. The same | 91 // Starts audio recording and does recognition after recording ends. The same |
91 // SpeechRecognizer instance can be used multiple times for speech recognition | 92 // SpeechRecognizer instance can be used multiple times for speech recognition |
92 // though each recognition request can be made only after the previous one | 93 // though each recognition request can be made only after the previous one |
93 // completes (i.e. after receiving Delegate::DidCompleteRecognition). | 94 // completes (i.e. after receiving Delegate::DidCompleteRecognition). |
94 bool StartRecording(); | 95 CONTENT_EXPORT bool StartRecording(); |
95 | 96 |
96 // Stops recording audio and starts recognition. | 97 // Stops recording audio and starts recognition. |
97 void StopRecording(); | 98 CONTENT_EXPORT void StopRecording(); |
98 | 99 |
99 // Stops recording audio and cancels recognition. Any audio recorded so far | 100 // Stops recording audio and cancels recognition. Any audio recorded so far |
100 // gets discarded. | 101 // gets discarded. |
101 void CancelRecognition(); | 102 CONTENT_EXPORT void CancelRecognition(); |
102 | 103 |
103 // AudioInputController::EventHandler methods. | 104 // AudioInputController::EventHandler methods. |
104 virtual void OnCreated(media::AudioInputController* controller) { } | 105 virtual void OnCreated(media::AudioInputController* controller) { } |
105 virtual void OnRecording(media::AudioInputController* controller) { } | 106 virtual void OnRecording(media::AudioInputController* controller) { } |
106 virtual void OnError(media::AudioInputController* controller, int error_code); | 107 virtual void OnError(media::AudioInputController* controller, int error_code); |
107 virtual void OnData(media::AudioInputController* controller, | 108 virtual void OnData(media::AudioInputController* controller, |
108 const uint8* data, | 109 const uint8* data, |
109 uint32 size); | 110 uint32 size); |
110 | 111 |
111 // SpeechRecognitionRequest::Delegate methods. | 112 // SpeechRecognitionRequest::Delegate methods. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 150 |
150 // This typedef is to workaround the issue with certain versions of | 151 // This typedef is to workaround the issue with certain versions of |
151 // Visual Studio where it gets confused between multiple Delegate | 152 // Visual Studio where it gets confused between multiple Delegate |
152 // classes and gives a C2500 error. (I saw this error on the try bots - | 153 // classes and gives a C2500 error. (I saw this error on the try bots - |
153 // the workaround was not needed for my machine). | 154 // the workaround was not needed for my machine). |
154 typedef SpeechRecognizer::Delegate SpeechRecognizerDelegate; | 155 typedef SpeechRecognizer::Delegate SpeechRecognizerDelegate; |
155 | 156 |
156 } // namespace speech_input | 157 } // namespace speech_input |
157 | 158 |
158 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ | 159 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ |
OLD | NEW |