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 #ifndef CHROME_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ | 5 #ifndef CHROME_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ |
6 #define CHROME_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ | 6 #define CHROME_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> |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 66 |
67 // Informs of a change in the captured audio level, useful if displaying | 67 // Informs of a change in the captured audio level, useful if displaying |
68 // a microphone volume indicator while recording. | 68 // a microphone volume indicator while recording. |
69 // The value of |volume| is in the [0.0, 1.0] range. | 69 // The value of |volume| is in the [0.0, 1.0] range. |
70 virtual void SetInputVolume(int caller_id, float volume) = 0; | 70 virtual void SetInputVolume(int caller_id, float volume) = 0; |
71 | 71 |
72 protected: | 72 protected: |
73 virtual ~Delegate() {} | 73 virtual ~Delegate() {} |
74 }; | 74 }; |
75 | 75 |
76 SpeechRecognizer(Delegate* delegate, int caller_id, | 76 SpeechRecognizer(Delegate* delegate, |
| 77 int caller_id, |
| 78 const std::string& language, |
77 const std::string& grammar); | 79 const std::string& grammar); |
78 ~SpeechRecognizer(); | 80 ~SpeechRecognizer(); |
79 | 81 |
80 // Starts audio recording and does recognition after recording ends. The same | 82 // Starts audio recording and does recognition after recording ends. The same |
81 // SpeechRecognizer instance can be used multiple times for speech recognition | 83 // SpeechRecognizer instance can be used multiple times for speech recognition |
82 // though each recognition request can be made only after the previous one | 84 // though each recognition request can be made only after the previous one |
83 // completes (i.e. after receiving Delegate::DidCompleteRecognition). | 85 // completes (i.e. after receiving Delegate::DidCompleteRecognition). |
84 bool StartRecording(); | 86 bool StartRecording(); |
85 | 87 |
86 // Stops recording audio and starts recognition. | 88 // Stops recording audio and starts recognition. |
(...skipping 24 matching lines...) Expand all Loading... |
111 void ReleaseAudioBuffers(); | 113 void ReleaseAudioBuffers(); |
112 void InformErrorAndCancelRecognition(ErrorCode error); | 114 void InformErrorAndCancelRecognition(ErrorCode error); |
113 | 115 |
114 void HandleOnError(int error_code); // Handles OnError in the IO thread. | 116 void HandleOnError(int error_code); // Handles OnError in the IO thread. |
115 | 117 |
116 // Handles OnData in the IO thread. Takes ownership of |data|. | 118 // Handles OnData in the IO thread. Takes ownership of |data|. |
117 void HandleOnData(std::string* data); | 119 void HandleOnData(std::string* data); |
118 | 120 |
119 Delegate* delegate_; | 121 Delegate* delegate_; |
120 int caller_id_; | 122 int caller_id_; |
| 123 std::string language_; |
121 std::string grammar_; | 124 std::string grammar_; |
122 | 125 |
123 // Buffer holding the recorded audio. Owns the strings inside the list. | 126 // Buffer holding the recorded audio. Owns the strings inside the list. |
124 typedef std::list<std::string*> AudioBufferQueue; | 127 typedef std::list<std::string*> AudioBufferQueue; |
125 AudioBufferQueue audio_buffers_; | 128 AudioBufferQueue audio_buffers_; |
126 | 129 |
127 scoped_ptr<SpeechRecognitionRequest> request_; | 130 scoped_ptr<SpeechRecognitionRequest> request_; |
128 scoped_refptr<media::AudioInputController> audio_controller_; | 131 scoped_refptr<media::AudioInputController> audio_controller_; |
129 scoped_ptr<SpeexEncoder> encoder_; | 132 scoped_ptr<SpeexEncoder> encoder_; |
130 Endpointer endpointer_; | 133 Endpointer endpointer_; |
131 int num_samples_recorded_; | 134 int num_samples_recorded_; |
132 float audio_level_; | 135 float audio_level_; |
133 | 136 |
134 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizer); | 137 DISALLOW_COPY_AND_ASSIGN(SpeechRecognizer); |
135 }; | 138 }; |
136 | 139 |
137 // This typedef is to workaround the issue with certain versions of | 140 // This typedef is to workaround the issue with certain versions of |
138 // Visual Studio where it gets confused between multiple Delegate | 141 // Visual Studio where it gets confused between multiple Delegate |
139 // classes and gives a C2500 error. (I saw this error on the try bots - | 142 // classes and gives a C2500 error. (I saw this error on the try bots - |
140 // the workaround was not needed for my machine). | 143 // the workaround was not needed for my machine). |
141 typedef SpeechRecognizer::Delegate SpeechRecognizerDelegate; | 144 typedef SpeechRecognizer::Delegate SpeechRecognizerDelegate; |
142 | 145 |
143 } // namespace speech_input | 146 } // namespace speech_input |
144 | 147 |
145 #endif // CHROME_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ | 148 #endif // CHROME_BROWSER_SPEECH_SPEECH_RECOGNIZER_H_ |
OLD | NEW |