ae1fddde812d4cea7c6c18625aa6ea3e9e96d803
[platform/framework/web/crosswalk-tizen.git] /
1 // Copyright 2016 Samsung Electronics Inc. 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_RECOGNIZER_IMPL_TIZEN_
6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_TIZEN_
7
8 #include <stt.h>
9 #include <vector>
10
11 #include "base/location.h"
12 #include "base/strings/string16.h"
13 #include "content/browser/speech/speech_recognizer.h"
14 #include "content/public/common/speech_recognition_result.h"
15
16 namespace content {
17
18 class SpeechRecognitionEventListener;
19 struct SpeechRecognitionError;
20
21 class CONTENT_EXPORT SpeechRecognizerImplTizen : public SpeechRecognizer {
22  public:
23   SpeechRecognizerImplTizen(SpeechRecognitionEventListener* listener,
24                             int session_id);
25
26   // SpeechRecognizer methods.
27   void StartRecognition(const std::string& device_id) override;
28   void AbortRecognition() override;
29   void StopAudioCapture() override;
30   bool IsActive() const override;
31   bool IsCapturingAudio() const override;
32
33  private:
34   ~SpeechRecognizerImplTizen() override;
35
36   bool Initialize();
37   void StartInternal();
38   void Destroy();
39   stt_state_e GetCurrentState() const;
40   bool ShouldStartRecognition() const;
41   void RecognitionResults(bool no_speech,
42                           const SpeechRecognitionResults& results);
43   void HandleSttError(stt_error_e error,
44                       const tracked_objects::Location& location);
45   void HandleSttResultError(const std::string error);
46   void RecognitionStarted();
47   void AudioCaptureEnd();
48   void EndRecognition(const tracked_objects::Location& location);
49
50   // Callbacks
51   static bool OnSupportedLanguages(stt_h stt,
52                                    const char* language,
53                                    void* user_data);
54   static void OnRecognitionResult(stt_h stt,
55                                   stt_result_event_e event,
56                                   const char** data,
57                                   int data_count,
58                                   const char* msg,
59                                   void* user_data);
60   static void OnStateChange(stt_h stt,
61                             stt_state_e previous,
62                             stt_state_e current,
63                             void* user_data);
64   static void OnError(stt_h stt, stt_error_e reason, void* user_data);
65
66   stt_h handle_;
67   std::string language_;
68   bool is_lang_supported_;
69   bool continuous_;
70   std::string recognition_type_;
71   bool is_aborted_;
72 };
73
74 }  // content
75
76 #endif  // BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_TIZEN_