Chromium Code Reviews| Index: content/browser/speech/speech_recognition_engine.h |
| diff --git a/content/browser/speech/speech_recognition_engine.h b/content/browser/speech/speech_recognition_engine.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3a2f0c28a2ce1d98e2ec452b8874b2b228f9dd1d |
| --- /dev/null |
| +++ b/content/browser/speech/speech_recognition_engine.h |
| @@ -0,0 +1,88 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_ENGINE_H_ |
| +#define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_ENGINE_H_ |
| +#pragma once |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "content/public/common/speech_recognition_result.h" |
| + |
| +namespace content { |
| +struct SpeechRecognitionResult; |
| +struct SpeechRecognitionError; |
| +} |
| + |
| +namespace speech { |
| + |
| +class AudioChunk; |
| + |
| +// This interface models the basic contract that a speech recognition engine, |
| +// either working locally or relying on a remote web-service, must obey. |
| +// The expected call sequence for exported methods is: |
| +// SpeechRecognitionBegins Mandatory at beginning of SR. |
| +// PushSpeechAudio For every audio chunk pushed. |
| +// SpeechAudioStreamComplete Finalize the audio stream (if no errors). |
| +// SpeechRecognitionEnds Mandatory at end of SR (even on errors). |
| +class SpeechRecognitionEngine { |
| + public: |
| + // Interface for receiving callbacks from this object. |
| + class Delegate { |
| + public: |
| + virtual void OnSpeechEngineResult( |
| + const content::SpeechRecognitionResult& result) = 0; |
| + virtual void OnSpeechEngineError( |
| + const content::SpeechRecognitionError& error) = 0; |
| + protected: |
| + virtual ~Delegate() {} |
| + }; |
| + |
| + virtual ~SpeechRecognitionEngine() {} |
| + |
| + // Notify the engine that we started the recognition, so it can prepare for |
| + // the upcoming PushSpeechAudio() calls. |
| + virtual void SpeechRecognitionBegins() = 0; |
| + |
| + // Notify the engine that we have ended (either gracefully or aborting) the |
| + // recognition, so it can cleanup. |
| + virtual void SpeechRecognitionEnds() = 0; |
| + |
| + // Push a chunk of uncompressed audio data, where the chunk length agrees with |
| + // DesiredAudioChunkDurationMs(), and bytes_per_sample agrees to the engine |
| + // configuration. |
| + virtual void PushSpeechAudio(const AudioChunk& data) = 0; |
| + |
| + // Notifies the engine that audio capture has completed and no more chunks |
| + // will be pushed. The engine can finalize the recognition in order to provide |
| + // a final result. |
| + virtual void SpeechAudioStreamComplete() = 0; |
| + |
| + // Checks wheter recognition of pushed audio data is pending. |
| + virtual bool IsRecognitionPending() const = 0; |
| + |
| + // Retrieves the desired duration, in milliseconds, of pushed AudioChunk(s). |
| + virtual int DesiredAudioChunkDurationMs() const = 0; |
| + |
| + // set_delegate detached from constructor for lazy dependency injection. |
| + void set_delegate(Delegate* delegate) {delegate_ = delegate;} |
| + |
| + protected: |
| + Delegate* sr_delegate() const {return delegate_;} |
|
hans
2012/03/16 11:12:56
should this just be called delegate() ?
nit: spac
Primiano Tucci (use gerrit)
2012/03/16 15:03:42
Hmm I named it so because there was a name clash i
|
| + |
| + private: |
| + Delegate* delegate_; |
| +}; |
| + |
| +// This typedef is to workaround the issue with certain versions of |
| +// Visual Studio where it gets confused between multiple Delegate |
| +// classes and gives a C2500 error. (I saw this error on the try bots - |
| +// the workaround was not needed for my machine). |
| +typedef SpeechRecognitionEngine::Delegate SpeechRecognitionEngineDelegate; |
| + |
| +} // namespace speech |
| + |
| +#endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_ENGINE_H_ |