OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_ENGINE_H_ | |
6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_ENGINE_H_ | |
7 #pragma once | |
8 | |
9 #include <string> | |
10 #include <vector> | |
11 | |
12 #include "base/basictypes.h" | |
13 #include "content/public/common/speech_recognition_result.h" | |
14 | |
15 namespace content { | |
16 struct SpeechRecognitionResult; | |
17 struct SpeechRecognitionError; | |
18 } | |
19 | |
20 namespace speech { | |
21 | |
22 class AudioChunk; | |
23 | |
24 // This interface models the basic contract that a speech recognition engine, | |
25 // either working locally or relying on a remote web-service, must obey. | |
26 // The expected call sequence for exported methods is: | |
27 // Initialize Mandatory at beginning of SR. | |
Satish
2012/03/21 13:29:48
Do you allow SpeechRecognitionEngine to be reused
Primiano Tucci (use gerrit)
2012/03/22 11:20:41
Done.
| |
28 // TakeAudioChunk For every audio chunk pushed. | |
29 // AudioChunksEnded Finalize the audio stream (omitted in case of errors). | |
30 // Cleanup Mandatory at end of SR (even on errors). | |
31 // No delegate callback is allowed before Initialize() or after Cleanup(). | |
32 class SpeechRecognitionEngine { | |
33 public: | |
34 // Interface for receiving callbacks from this object. | |
35 class Delegate { | |
36 public: | |
37 virtual void OnSpeechEngineResult( | |
Satish
2012/03/21 13:29:48
SpeechEngine -> SpeechRecognitionEngine.
Add comme
Primiano Tucci (use gerrit)
2012/03/22 11:20:41
Done.
| |
38 const content::SpeechRecognitionResult& result) = 0; | |
39 virtual void OnSpeechEngineError( | |
40 const content::SpeechRecognitionError& error) = 0; | |
41 protected: | |
Satish
2012/03/21 13:29:48
add newline above
Primiano Tucci (use gerrit)
2012/03/22 11:20:41
Done.
| |
42 virtual ~Delegate() {} | |
43 }; | |
44 | |
45 virtual ~SpeechRecognitionEngine() {} | |
46 | |
47 // Prepare for upcoming TakeAudioChunk() calls. | |
Satish
2012/03/21 13:29:48
reword comment to explain this should be called wh
Primiano Tucci (use gerrit)
2012/03/22 11:20:41
Done.
| |
48 virtual void Initialize() = 0; | |
49 | |
50 // End any recognition activity and don't make any further callback. | |
51 virtual void Cleanup() = 0; | |
52 | |
53 // Push a chunk of uncompressed audio data, where the chunk length agrees with | |
54 // GetDesiredAudioChunkDurationMs(), and bytes_per_sample agrees to the engine | |
Satish
2012/03/21 13:29:48
No need to mention this in the comment if they are
Primiano Tucci (use gerrit)
2012/03/22 11:20:41
Removed the bytes_per_sample as it is DCHECKed. Th
| |
55 // configuration. | |
56 virtual void TakeAudioChunk(const AudioChunk& data) = 0; | |
57 | |
58 // Notifies the engine that audio capture has completed and no more chunks | |
59 // will be pushed. The engine, however, can still provide further results | |
60 // using the audio chunks collected so far. | |
61 virtual void AudioChunksEnded() = 0; | |
62 | |
63 // Checks wheter recognition of pushed audio data is pending. | |
64 virtual bool IsRecognitionPending() const = 0; | |
65 | |
66 // Retrieves the desired duration, in milliseconds, of pushed AudioChunk(s). | |
67 virtual int GetDesiredAudioChunkDurationMs() const = 0; | |
68 | |
69 // set_delegate detached from constructor for lazy dependency injection. | |
70 void set_delegate(Delegate* delegate) { delegate_ = delegate; } | |
71 | |
72 protected: | |
73 Delegate* delegate() const { return delegate_; } | |
74 | |
75 private: | |
76 Delegate* delegate_; | |
77 }; | |
78 | |
79 // This typedef is to workaround the issue with certain versions of | |
80 // Visual Studio where it gets confused between multiple Delegate | |
81 // classes and gives a C2500 error. (I saw this error on the try bots - | |
82 // the workaround was not needed for my machine). | |
83 typedef SpeechRecognitionEngine::Delegate SpeechRecognitionEngineDelegate; | |
84 | |
85 } // namespace speech | |
86 | |
87 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_ENGINE_H_ | |
OLD | NEW |