| 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_REQUEST_H_ | |
| 6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_REQUEST_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "content/common/content_export.h" | |
| 15 #include "content/public/common/url_fetcher_delegate.h" | |
| 16 #include "googleurl/src/gurl.h" | |
| 17 | |
| 18 class URLFetcher; | |
| 19 | |
| 20 namespace content { | |
| 21 struct SpeechRecognitionResult; | |
| 22 } | |
| 23 | |
| 24 namespace net { | |
| 25 class URLRequestContextGetter; | |
| 26 } | |
| 27 | |
| 28 namespace speech { | |
| 29 | |
| 30 class AudioChunk; | |
| 31 | |
| 32 // Provides a simple interface for sending recorded speech data to the server | |
| 33 // and get back recognition results. | |
| 34 class SpeechRecognitionRequest : public content::URLFetcherDelegate { | |
| 35 public: | |
| 36 // ID passed to URLFetcher::Create(). Used for testing. | |
| 37 CONTENT_EXPORT static int url_fetcher_id_for_tests; | |
| 38 | |
| 39 // Interface for receiving callbacks from this object. | |
| 40 class CONTENT_EXPORT Delegate { | |
| 41 public: | |
| 42 virtual void SetRecognitionResult( | |
| 43 const content::SpeechRecognitionResult& result) = 0; | |
| 44 | |
| 45 protected: | |
| 46 virtual ~Delegate() {} | |
| 47 }; | |
| 48 | |
| 49 // |url| is the server address to which the request wil be sent. | |
| 50 CONTENT_EXPORT SpeechRecognitionRequest(net::URLRequestContextGetter* context, | |
| 51 Delegate* delegate); | |
| 52 | |
| 53 CONTENT_EXPORT virtual ~SpeechRecognitionRequest(); | |
| 54 | |
| 55 // Sends a new request with the given audio data, returns true if successful. | |
| 56 // The same object can be used to send multiple requests but only after the | |
| 57 // previous request has completed. | |
| 58 CONTENT_EXPORT void Start(const std::string& language, | |
| 59 const std::string& grammar, | |
| 60 bool filter_profanities, | |
| 61 const std::string& hardware_info, | |
| 62 const std::string& origin_url, | |
| 63 const std::string& content_type); | |
| 64 | |
| 65 // Send a single chunk of audio immediately to the server. | |
| 66 CONTENT_EXPORT void UploadAudioChunk(const AudioChunk& audio_chunk, | |
| 67 bool is_last_chunk); | |
| 68 | |
| 69 CONTENT_EXPORT bool HasPendingRequest() { return url_fetcher_ != NULL; } | |
| 70 | |
| 71 // content::URLFetcherDelegate methods. | |
| 72 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; | |
| 73 | |
| 74 private: | |
| 75 scoped_refptr<net::URLRequestContextGetter> url_context_; | |
| 76 Delegate* delegate_; | |
| 77 scoped_ptr<content::URLFetcher> url_fetcher_; | |
| 78 | |
| 79 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionRequest); | |
| 80 }; | |
| 81 | |
| 82 // This typedef is to workaround the issue with certain versions of | |
| 83 // Visual Studio where it gets confused between multiple Delegate | |
| 84 // classes and gives a C2500 error. (I saw this error on the try bots - | |
| 85 // the workaround was not needed for my machine). | |
| 86 typedef SpeechRecognitionRequest::Delegate SpeechRecognitionRequestDelegate; | |
| 87 | |
| 88 } // namespace speech | |
| 89 | |
| 90 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_REQUEST_H_ | |
| OLD | NEW |