OLD | NEW |
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_RECOGNITION_ENGINE_H_ | 5 #ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_ENGINE_H_ |
6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_ENGINE_H_ | 6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_ENGINE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
12 #include "content/public/common/speech_recognition_grammar.h" | 12 #include "content/public/common/speech_recognition_grammar.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
| 15 |
| 16 class AudioChunk; |
15 struct SpeechRecognitionResult; | 17 struct SpeechRecognitionResult; |
16 struct SpeechRecognitionError; | 18 struct SpeechRecognitionError; |
17 } | |
18 | |
19 namespace speech { | |
20 | |
21 class AudioChunk; | |
22 | 19 |
23 // This interface models the basic contract that a speech recognition engine, | 20 // This interface models the basic contract that a speech recognition engine, |
24 // either working locally or relying on a remote web-service, must obey. | 21 // either working locally or relying on a remote web-service, must obey. |
25 // The expected call sequence for exported methods is: | 22 // The expected call sequence for exported methods is: |
26 // StartRecognition Mandatory at beginning of SR. | 23 // StartRecognition Mandatory at beginning of SR. |
27 // TakeAudioChunk For every audio chunk pushed. | 24 // TakeAudioChunk For every audio chunk pushed. |
28 // AudioChunksEnded Finalize the audio stream (omitted in case of errors). | 25 // AudioChunksEnded Finalize the audio stream (omitted in case of errors). |
29 // EndRecognition Mandatory at end of SR (even on errors). | 26 // EndRecognition Mandatory at end of SR (even on errors). |
30 // No delegate callbacks are allowed before StartRecognition or after | 27 // No delegate callbacks are allowed before StartRecognition or after |
31 // EndRecognition. If a recognition was started, the caller can free the | 28 // EndRecognition. If a recognition was started, the caller can free the |
32 // SpeechRecognitionEngine only after calling EndRecognition. | 29 // SpeechRecognitionEngine only after calling EndRecognition. |
33 class SpeechRecognitionEngine { | 30 class SpeechRecognitionEngine { |
34 public: | 31 public: |
35 // Interface for receiving callbacks from this object. | 32 // Interface for receiving callbacks from this object. |
36 class Delegate { | 33 class Delegate { |
37 public: | 34 public: |
38 // Called whenever a result is retrieved. It might be issued several times, | 35 // Called whenever a result is retrieved. It might be issued several times, |
39 // (e.g., in the case of continuous speech recognition engine | 36 // (e.g., in the case of continuous speech recognition engine |
40 // implementations). | 37 // implementations). |
41 virtual void OnSpeechRecognitionEngineResult( | 38 virtual void OnSpeechRecognitionEngineResult( |
42 const content::SpeechRecognitionResult& result) = 0; | 39 const SpeechRecognitionResult& result) = 0; |
43 virtual void OnSpeechRecognitionEngineError( | 40 virtual void OnSpeechRecognitionEngineError( |
44 const content::SpeechRecognitionError& error) = 0; | 41 const SpeechRecognitionError& error) = 0; |
45 | 42 |
46 protected: | 43 protected: |
47 virtual ~Delegate() {} | 44 virtual ~Delegate() {} |
48 }; | 45 }; |
49 | 46 |
50 // Remote engine configuration. | 47 // Remote engine configuration. |
51 struct CONTENT_EXPORT Config { | 48 struct CONTENT_EXPORT Config { |
52 Config(); | 49 Config(); |
53 ~Config(); | 50 ~Config(); |
54 | 51 |
55 std::string language; | 52 std::string language; |
56 content::SpeechRecognitionGrammarArray grammars; | 53 SpeechRecognitionGrammarArray grammars; |
57 bool filter_profanities; | 54 bool filter_profanities; |
58 bool continuous; | 55 bool continuous; |
59 bool interim_results; | 56 bool interim_results; |
60 uint32 max_hypotheses; | 57 uint32 max_hypotheses; |
61 std::string hardware_info; | 58 std::string hardware_info; |
62 std::string origin_url; | 59 std::string origin_url; |
63 int audio_sample_rate; | 60 int audio_sample_rate; |
64 int audio_num_bits_per_sample; | 61 int audio_num_bits_per_sample; |
65 }; | 62 }; |
66 | 63 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 private: | 100 private: |
104 Delegate* delegate_; | 101 Delegate* delegate_; |
105 }; | 102 }; |
106 | 103 |
107 // These typedefs are to workaround the issue with certain versions of | 104 // These typedefs are to workaround the issue with certain versions of |
108 // Visual Studio where it gets confused between multiple Delegate | 105 // Visual Studio where it gets confused between multiple Delegate |
109 // classes and gives a C2500 error. | 106 // classes and gives a C2500 error. |
110 typedef SpeechRecognitionEngine::Delegate SpeechRecognitionEngineDelegate; | 107 typedef SpeechRecognitionEngine::Delegate SpeechRecognitionEngineDelegate; |
111 typedef SpeechRecognitionEngine::Config SpeechRecognitionEngineConfig; | 108 typedef SpeechRecognitionEngine::Config SpeechRecognitionEngineConfig; |
112 | 109 |
113 } // namespace speech | 110 } // namespace content |
114 | 111 |
115 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_ENGINE_H_ | 112 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_ENGINE_H_ |
OLD | NEW |