summaryrefslogtreecommitdiffstats
path: root/content/browser/speech/speech_recognition_engine.h
diff options
context:
space:
mode:
authorprimiano@chromium.org <primiano@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-26 11:56:02 +0000
committerprimiano@chromium.org <primiano@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-26 11:56:02 +0000
commit7527adf41d86050b32e0f67a93e0a6aae24ec22c (patch)
treed27ac2cc5fb67fc1ae777d92ce1159bf47bb7b6c /content/browser/speech/speech_recognition_engine.h
parent5ce89bc5b409d25b58214c3d3a3667e989675033 (diff)
downloadchromium_src-7527adf41d86050b32e0f67a93e0a6aae24ec22c.zip
chromium_src-7527adf41d86050b32e0f67a93e0a6aae24ec22c.tar.gz
chromium_src-7527adf41d86050b32e0f67a93e0a6aae24ec22c.tar.bz2
speech_recognition_request
- Renamed speech_recognition_request to google_one_shot_remote_engine - Audio encoder moved here (previously was in speech_recognizer). Rationale: Audio encoding is not a requirement of speech recognition. It is a need of the google_one_shot_remote_engine, due to its remote nature. speech_recognition_engine - Extracted the interface SpeechRecognitionEngine (and, accordingly, Delegate) from the former speech_recognition_request. Rationale: google_one_shot_remote_engine is just one of the possible engines (yet currently the only one) that can be exploited to recognize speech. speech_recognition_result - Added SpeechRecognitionError, encapsulating the error code and further error details (for specializing audio errors, since chrome needs them). speech_recognition_manager - Minor adaptions to the new speech_recognizer.cc - Replaced the SpeechRecognitionRequestDelegate interface with the brand new speech_recognition_event_listener BUG=116954 TEST=none Review URL: http://codereview.chromium.org/9663066 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128896 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/speech/speech_recognition_engine.h')
-rw-r--r--content/browser/speech/speech_recognition_engine.h92
1 files changed, 92 insertions, 0 deletions
diff --git a/content/browser/speech/speech_recognition_engine.h b/content/browser/speech/speech_recognition_engine.h
new file mode 100644
index 0000000..5b64d67
--- /dev/null
+++ b/content/browser/speech/speech_recognition_engine.h
@@ -0,0 +1,92 @@
+// 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"
+
+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:
+// StartRecognition Mandatory at beginning of SR.
+// TakeAudioChunk For every audio chunk pushed.
+// AudioChunksEnded Finalize the audio stream (omitted in case of errors).
+// EndRecognition Mandatory at end of SR (even on errors).
+// No delegate callback is allowed before Initialize() or after Cleanup().
+class SpeechRecognitionEngine {
+ public:
+ // Interface for receiving callbacks from this object.
+ class Delegate {
+ public:
+ // Called whenever a result is retrieved. It might be issued several times,
+ // (e.g., in the case of continuous speech recognition engine
+ // implementations).
+ virtual void OnSpeechRecognitionEngineResult(
+ const content::SpeechRecognitionResult& result) = 0;
+ virtual void OnSpeechRecognitionEngineError(
+ const content::SpeechRecognitionError& error) = 0;
+
+ protected:
+ virtual ~Delegate() {}
+ };
+
+ virtual ~SpeechRecognitionEngine() {}
+
+ // Called when the speech recognition begins, before any TakeAudioChunk call.
+ virtual void StartRecognition() = 0;
+
+ // End any recognition activity and don't make any further callback.
+ // Must be always called to close the corresponding StartRecognition call,
+ // even in case of errors.
+ // No further TakeAudioChunk/AudioChunksEnded calls are allowed after this.
+ virtual void EndRecognition() = 0;
+
+ // Push a chunk of uncompressed audio data, where the chunk length agrees with
+ // GetDesiredAudioChunkDurationMs().
+ virtual void TakeAudioChunk(const AudioChunk& data) = 0;
+
+ // Notifies the engine that audio capture has completed and no more chunks
+ // will be pushed. The engine, however, can still provide further results
+ // using the audio chunks collected so far.
+ virtual void AudioChunksEnded() = 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 GetDesiredAudioChunkDurationMs() const = 0;
+
+ // set_delegate detached from constructor for lazy dependency injection.
+ void set_delegate(Delegate* delegate) { delegate_ = delegate; }
+
+ protected:
+ Delegate* delegate() const { return delegate_; }
+
+ 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_