Tizen 2.1 base
[framework/osp/speech.git] / src / stt / FUixSpeechSpeechToText.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file    FUixSpeechSpeechToText.cpp
20  * @brief   This is the implementation file for the SpeechToText class.
21  *
22  * This files contains implementation of the SpeechToText class.
23  */
24
25 #include <FLclLocale.h>
26 #include <FUixSpeechSpeechToText.h>
27 #include <FBaseSysLog.h>
28 #include <FUixSpeech_SpeechToTextImpl.h>
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Locales;
33
34 namespace Tizen { namespace Uix { namespace Speech
35 {
36
37 SpeechToText::SpeechToText(void)
38     : __pSpeechToTextImpl(null)
39 {
40 }
41
42 SpeechToText::~SpeechToText(void)
43 {
44     delete __pSpeechToTextImpl;
45 }
46
47 result
48 SpeechToText::Construct(ISpeechToTextEventListener& listener)
49 {
50     SysAssertf(__pSpeechToTextImpl == null, "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
51
52     __pSpeechToTextImpl = new (std::nothrow) _SpeechToTextImpl();
53         SysTryReturn(NID_UIX_SPEECH, __pSpeechToTextImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
54
55     return __pSpeechToTextImpl->Construct(listener);
56 }
57
58 result
59 SpeechToText::Initialize(void)
60 {
61     SysAssertf(__pSpeechToTextImpl != null, "Not yet constructed! Construct() should be called before use.");
62
63     return __pSpeechToTextImpl->Initialize();
64 }
65
66 result
67 SpeechToText::Start(void)
68 {
69     SysAssertf(__pSpeechToTextImpl != null, "Not yet constructed! Construct() should be called before use.");
70
71     return __pSpeechToTextImpl->Start();
72 }
73
74 result
75 SpeechToText::Stop(void)
76 {
77     SysAssertf(__pSpeechToTextImpl != null, "Not yet constructed! Construct() should be called before use.");
78
79     return __pSpeechToTextImpl->Stop();
80 }
81
82 result
83 SpeechToText::Cancel(void)
84 {
85     SysAssertf(__pSpeechToTextImpl != null, "Not yet constructed! Construct() should be called before use.");
86
87     return __pSpeechToTextImpl->Cancel();
88 }
89
90 result
91 SpeechToText::SetLocale(const Locale& locale)
92 {
93     SysAssertf(__pSpeechToTextImpl != null, "Not yet constructed! Construct() should be called before use.");
94
95     return __pSpeechToTextImpl->SetLocale(locale);
96 }
97
98 Locale
99 SpeechToText::GetLocale(void) const
100 {
101     SysAssertf(__pSpeechToTextImpl != null, "Not yet constructed! Construct() should be called before use.");
102
103     return __pSpeechToTextImpl->GetLocale();
104 }
105
106 const Tizen::Base::Collection::IList*
107 SpeechToText::GetSupportedLocales(void) const
108 {
109     SysAssertf(__pSpeechToTextImpl != null, "Not yet constructed! Construct() should be called before use.");
110
111     return __pSpeechToTextImpl->GetSupportedLocales();
112 }
113
114 bool
115 SpeechToText::IsLocaleSupported(const Locale& locale) const
116 {
117     SysAssertf(__pSpeechToTextImpl != null, "Not yet constructed! Construct() should be called before use.");
118
119     return __pSpeechToTextImpl->IsLocaleSupported(locale);
120 }
121
122 result
123 SpeechToText::SetGrammar(SpeechToTextGrammar grammar)
124 {
125     SysAssertf(__pSpeechToTextImpl != null, "Not yet constructed! Construct() should be called before use.");
126
127     return __pSpeechToTextImpl->SetGrammar(grammar);
128 }
129
130 SpeechToTextGrammar
131 SpeechToText::GetGrammar(void) const
132 {
133     SysAssertf(__pSpeechToTextImpl != null, "Not yet constructed! Construct() should be called before use.");
134
135     return __pSpeechToTextImpl->GetGrammar();
136 }
137
138 result
139 SpeechToText::SetSilenceDetectionEnabled(bool enable)
140 {
141     SysAssertf(__pSpeechToTextImpl != null, "Not yet constructed! Construct() should be called before use.");
142
143     return __pSpeechToTextImpl->SetSilenceDetectionEnabled(enable);
144 }
145
146 bool
147 SpeechToText::IsSilenceDetectionEnabled(void) const
148 {
149     SysAssertf(__pSpeechToTextImpl != null, "Not yet constructed! Construct() should be called before use.");
150
151     return __pSpeechToTextImpl->IsSilenceDetectionEnabled();
152 }
153
154 SpeechToTextStatus
155 SpeechToText::GetCurrentStatus(void) const
156 {
157     SysAssertf(__pSpeechToTextImpl != null, "Not yet constructed! Construct() should be called before use.");
158
159     return __pSpeechToTextImpl->GetCurrentStatus();
160 }
161
162 } } } // Tizen::Uix::Speech
163