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.
5 #ifndef CONTENT_BROWSER_SPEECH_GOOGLE_ONE_SHOT_REMOTE_ENGINE_H_
6 #define CONTENT_BROWSER_SPEECH_GOOGLE_ONE_SHOT_REMOTE_ENGINE_H_
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "content/browser/speech/audio_encoder.h"
14 #include "content/browser/speech/speech_recognition_engine.h"
15 #include "content/common/content_export.h"
16 #include "net/url_request/url_fetcher_delegate.h"
19 class URLRequestContextGetter
;
24 // Implements a SpeechRecognitionEngine by means of remote interaction with
25 // Google speech recognition webservice.
26 class CONTENT_EXPORT GoogleOneShotRemoteEngine
27 : public NON_EXPORTED_BASE(SpeechRecognitionEngine
),
28 public net::URLFetcherDelegate
{
30 // Duration of each audio packet.
31 static const int kAudioPacketIntervalMs
;
32 // ID passed to URLFetcher::Create(). Used for testing.
33 static int url_fetcher_id_for_tests
;
35 explicit GoogleOneShotRemoteEngine(net::URLRequestContextGetter
* context
);
36 ~GoogleOneShotRemoteEngine() override
;
38 // SpeechRecognitionEngine methods.
39 void SetConfig(const SpeechRecognitionEngineConfig
& config
) override
;
40 void StartRecognition() override
;
41 void EndRecognition() override
;
42 void TakeAudioChunk(const AudioChunk
& data
) override
;
43 void AudioChunksEnded() override
;
44 bool IsRecognitionPending() const override
;
45 int GetDesiredAudioChunkDurationMs() const override
;
47 // net::URLFetcherDelegate methods.
48 void OnURLFetchComplete(const net::URLFetcher
* source
) override
;
51 SpeechRecognitionEngineConfig config_
;
52 scoped_ptr
<net::URLFetcher
> url_fetcher_
;
53 scoped_refptr
<net::URLRequestContextGetter
> url_context_
;
54 scoped_ptr
<AudioEncoder
> encoder_
;
56 DISALLOW_COPY_AND_ASSIGN(GoogleOneShotRemoteEngine
);
59 } // namespace content
61 #endif // CONTENT_BROWSER_SPEECH_GOOGLE_ONE_SHOT_REMOTE_ENGINE_H_