Chromium Code Reviews| 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 // SpeechRecognitionBegins Mandatory at beginning of SR. | |
| 28 // PushSpeechAudio For every audio chunk pushed. | |
| 29 // SpeechAudioStreamComplete Finalize the audio stream (if no errors). | |
| 30 // SpeechRecognitionEnds Mandatory at end of SR (even on errors). | |
| 31 class SpeechRecognitionEngine { | |
| 32 public: | |
| 33 // Interface for receiving callbacks from this object. | |
| 34 class Delegate { | |
| 35 public: | |
| 36 virtual void OnSpeechEngineResult( | |
|
Satish
2012/03/16 17:00:35
OnSpeech -> OnSpeechRecognition ?
Primiano Tucci (use gerrit)
2012/03/20 13:14:50
I'd prefer OnSpeechEngine since this interface mod
| |
| 37 const content::SpeechRecognitionResult& result) = 0; | |
| 38 virtual void OnSpeechEngineError( | |
|
Satish
2012/03/16 17:00:35
ditto
Primiano Tucci (use gerrit)
2012/03/20 13:14:50
Same as above.
On 2012/03/16 17:00:35, Satish wrot
| |
| 39 const content::SpeechRecognitionError& error) = 0; | |
| 40 protected: | |
| 41 virtual ~Delegate() {} | |
| 42 }; | |
| 43 | |
| 44 virtual ~SpeechRecognitionEngine() {} | |
| 45 | |
| 46 // Notify the engine that we started the recognition, so it can prepare for | |
| 47 // the upcoming PushSpeechAudio() calls. | |
| 48 virtual void SpeechRecognitionBegins() = 0; | |
|
Satish
2012/03/16 17:00:35
perhaps 'StartSession' or something similar?
Primiano Tucci (use gerrit)
2012/03/20 13:14:50
Agree with the ambiguity of names.
However I don't
| |
| 49 | |
| 50 // Notify the engine that we have ended (either gracefully or aborting) the | |
|
Satish
2012/03/16 17:00:35
I don't see a way to abort in this class. Should t
Primiano Tucci (use gerrit)
2012/03/20 13:14:50
Basically, Cleanup() does it, since can be called
| |
| 51 // recognition, so it can cleanup. | |
| 52 virtual void SpeechRecognitionEnds() = 0; | |
|
Satish
2012/03/16 17:00:35
EndSession ?
Primiano Tucci (use gerrit)
2012/03/20 13:14:50
Cleanup?
On 2012/03/16 17:00:35, Satish wrote:
| |
| 53 | |
| 54 // Push a chunk of uncompressed audio data, where the chunk length agrees with | |
| 55 // DesiredAudioChunkDurationMs(), and bytes_per_sample agrees to the engine | |
| 56 // configuration. | |
| 57 virtual void PushSpeechAudio(const AudioChunk& data) = 0; | |
|
Satish
2012/03/16 17:00:35
AddAudioChunk or something similar?
Primiano Tucci (use gerrit)
2012/03/20 13:14:50
TakeAudioChunk?
On 2012/03/16 17:00:35, Satish wro
| |
| 58 | |
| 59 // Notifies the engine that audio capture has completed and no more chunks | |
| 60 // will be pushed. The engine can finalize the recognition in order to provide | |
|
Satish
2012/03/16 17:00:35
"finalize the recognition in order to provide a fi
Primiano Tucci (use gerrit)
2012/03/20 13:14:50
Done.
| |
| 61 // a final result. | |
| 62 virtual void SpeechAudioStreamComplete() = 0; | |
|
Satish
2012/03/16 17:00:35
AudioCompleted or something similar?
Primiano Tucci (use gerrit)
2012/03/20 13:14:50
AudioChunksEnded?
On 2012/03/16 17:00:35, Satish w
| |
| 63 | |
| 64 // Checks wheter recognition of pushed audio data is pending. | |
| 65 virtual bool IsRecognitionPending() const = 0; | |
| 66 | |
| 67 // Retrieves the desired duration, in milliseconds, of pushed AudioChunk(s). | |
| 68 virtual int DesiredAudioChunkDurationMs() const = 0; | |
|
Satish
2012/03/16 17:00:35
Desired -> GetDesired ?
Primiano Tucci (use gerrit)
2012/03/20 13:14:50
Done.
| |
| 69 | |
| 70 // set_delegate detached from constructor for lazy dependency injection. | |
| 71 void set_delegate(Delegate* delegate) { delegate_ = delegate; } | |
| 72 | |
| 73 protected: | |
| 74 Delegate* delegate() const { return delegate_; } | |
| 75 | |
| 76 private: | |
|
Satish
2012/03/16 17:00:35
add DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionEngi
Primiano Tucci (use gerrit)
2012/03/20 13:14:50
Done.
| |
| 77 Delegate* delegate_; | |
| 78 }; | |
| 79 | |
| 80 // This typedef is to workaround the issue with certain versions of | |
| 81 // Visual Studio where it gets confused between multiple Delegate | |
| 82 // classes and gives a C2500 error. (I saw this error on the try bots - | |
| 83 // the workaround was not needed for my machine). | |
| 84 typedef SpeechRecognitionEngine::Delegate SpeechRecognitionEngineDelegate; | |
| 85 | |
| 86 } // namespace speech | |
| 87 | |
| 88 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_ENGINE_H_ | |
| OLD | NEW |