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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | |
11 | 10 |
12 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "content/public/common/speech_recognition_grammar.h" | |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 struct SpeechRecognitionResult; | 15 struct SpeechRecognitionResult; |
16 struct SpeechRecognitionError; | 16 struct SpeechRecognitionError; |
17 } | 17 } |
18 | 18 |
19 namespace speech { | 19 namespace speech { |
20 | 20 |
21 class AudioChunk; | 21 class AudioChunk; |
22 | 22 |
23 struct SpeechRecognitionEngineConfig { | |
Satish
2012/04/27 10:04:41
move this as an inner class of SpeechRecognitionEn
Primiano Tucci (use gerrit)
2012/04/27 15:58:44
Done.
| |
24 SpeechRecognitionEngineConfig(); | |
25 ~SpeechRecognitionEngineConfig(); | |
26 | |
27 std::string language; | |
28 content::SpeechRecognitionGrammarArray grammars; | |
29 bool filter_profanities; | |
30 std::string hardware_info; | |
31 std::string origin_url; | |
32 int audio_sample_rate; | |
33 int audio_num_bits_per_sample; | |
34 }; | |
35 | |
23 // This interface models the basic contract that a speech recognition engine, | 36 // This interface models the basic contract that a speech recognition engine, |
24 // either working locally or relying on a remote web-service, must obey. | 37 // either working locally or relying on a remote web-service, must obey. |
25 // The expected call sequence for exported methods is: | 38 // The expected call sequence for exported methods is: |
26 // StartRecognition Mandatory at beginning of SR. | 39 // StartRecognition Mandatory at beginning of SR. |
27 // TakeAudioChunk For every audio chunk pushed. | 40 // TakeAudioChunk For every audio chunk pushed. |
28 // AudioChunksEnded Finalize the audio stream (omitted in case of errors). | 41 // AudioChunksEnded Finalize the audio stream (omitted in case of errors). |
29 // EndRecognition Mandatory at end of SR (even on errors). | 42 // EndRecognition Mandatory at end of SR (even on errors). |
30 // No delegate callback is allowed before Initialize() or after Cleanup(). | 43 // No delegate callbacks are allowed before StartRecognition or after |
44 // EndRecognition. If a recognition was started, the caller can free the | |
45 // SpeechRecognitionEnding only after calling EndRecognition. | |
Satish
2012/04/27 10:04:41
Ending -> Engine
Primiano Tucci (use gerrit)
2012/04/27 15:58:44
Done.
| |
31 class SpeechRecognitionEngine { | 46 class SpeechRecognitionEngine { |
32 public: | 47 public: |
33 // Interface for receiving callbacks from this object. | 48 // Interface for receiving callbacks from this object. |
34 class Delegate { | 49 class Delegate { |
35 public: | 50 public: |
36 // Called whenever a result is retrieved. It might be issued several times, | 51 // Called whenever a result is retrieved. It might be issued several times, |
37 // (e.g., in the case of continuous speech recognition engine | 52 // (e.g., in the case of continuous speech recognition engine |
38 // implementations). | 53 // implementations). |
39 virtual void OnSpeechRecognitionEngineResult( | 54 virtual void OnSpeechRecognitionEngineResult( |
40 const content::SpeechRecognitionResult& result) = 0; | 55 const content::SpeechRecognitionResult& result) = 0; |
41 virtual void OnSpeechRecognitionEngineError( | 56 virtual void OnSpeechRecognitionEngineError( |
42 const content::SpeechRecognitionError& error) = 0; | 57 const content::SpeechRecognitionError& error) = 0; |
43 | 58 |
44 protected: | 59 protected: |
45 virtual ~Delegate() {} | 60 virtual ~Delegate() {} |
46 }; | 61 }; |
47 | 62 |
48 virtual ~SpeechRecognitionEngine() {} | 63 virtual ~SpeechRecognitionEngine() {} |
49 | 64 |
65 // Set/change the recognition engine configuration. It is not allowed to call | |
66 // this function while a recognition is ongoing. | |
67 virtual void SetConfig(const SpeechRecognitionEngineConfig& config) = 0; | |
68 | |
50 // Called when the speech recognition begins, before any TakeAudioChunk call. | 69 // Called when the speech recognition begins, before any TakeAudioChunk call. |
51 virtual void StartRecognition() = 0; | 70 virtual void StartRecognition() = 0; |
52 | 71 |
53 // End any recognition activity and don't make any further callback. | 72 // End any recognition activity and don't make any further callback. |
54 // Must be always called to close the corresponding StartRecognition call, | 73 // Must be always called to close the corresponding StartRecognition call, |
55 // even in case of errors. | 74 // even in case of errors. |
56 // No further TakeAudioChunk/AudioChunksEnded calls are allowed after this. | 75 // No further TakeAudioChunk/AudioChunksEnded calls are allowed after this. |
57 virtual void EndRecognition() = 0; | 76 virtual void EndRecognition() = 0; |
58 | 77 |
59 // Push a chunk of uncompressed audio data, where the chunk length agrees with | 78 // Push a chunk of uncompressed audio data, where the chunk length agrees with |
(...skipping 23 matching lines...) Expand all Loading... | |
83 | 102 |
84 // This typedef is to workaround the issue with certain versions of | 103 // This typedef is to workaround the issue with certain versions of |
85 // Visual Studio where it gets confused between multiple Delegate | 104 // Visual Studio where it gets confused between multiple Delegate |
86 // classes and gives a C2500 error. (I saw this error on the try bots - | 105 // classes and gives a C2500 error. (I saw this error on the try bots - |
87 // the workaround was not needed for my machine). | 106 // the workaround was not needed for my machine). |
88 typedef SpeechRecognitionEngine::Delegate SpeechRecognitionEngineDelegate; | 107 typedef SpeechRecognitionEngine::Delegate SpeechRecognitionEngineDelegate; |
89 | 108 |
90 } // namespace speech | 109 } // namespace speech |
91 | 110 |
92 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_ENGINE_H_ | 111 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_ENGINE_H_ |
OLD | NEW |