2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 3.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
9 // http://www.apache.org/licenses/LICENSE-3.0
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.
19 * @file FUixSpeechSpeechToText.h
20 * @brief This is the header file for the %SpeechToText class.
22 * This header file contains the declarations of the %SpeechToText class.
25 #ifndef _FUIX_SPEECH_SPEECH_TO_TEXT_H_
26 #define _FUIX_SPEECH_SPEECH_TO_TEXT_H_
28 #include <FBaseObject.h>
29 #include <FBaseDataType.h>
30 #include <FUixSpeechSpeechToTextTypes.h>
31 #include <FUixSpeechISpeechToTextEventListener.h>
33 namespace Tizen { namespace Base
38 namespace Tizen { namespace Base { namespace Collection
42 namespace Tizen { namespace Locales
47 namespace Tizen { namespace Uix { namespace Speech
50 class _SpeechToTextImpl;
54 * @brief This class is used to convert spoken words into text.
58 * @remarks @b Header @b %file: @b \#include @b <FUix.h> @n
59 * @b Library : @b osp-speech-stt
61 * The %SpeechToText class converts spoken words into text.
63 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/uix/speech_to_text.htm">Speech-To-Text</a>.
65 * The following example demonstrates how to use the %SpeechToText class. @n
66 * In the example, the Start() method is called after invoking the ISpeechToTextEventListener::OnSpeechToTextInitialized() method.
69 * //Sample code for SpeechToTextSample.h
72 * using namespace Tizen::Uix::Speech;
74 * class SpeechToTextSample : public ISpeechToTextEventListener
77 * SpeechToTextSample(void);
78 * virtual ~SpeechToTextSample(void);
80 * bool Initialize(void);
83 * virtual void OnSpeechToTextInitialized(void);
84 * virtual void OnSpeechToTextStatusChanged(Tizen::Uix::Speech::SpeechToTextStatus status);
85 * virtual void OnSpeechToTextErrorOccurred(Tizen::Uix::Speech::SpeechToTextError error);
86 * virtual void OnSpeechToTextCompleted(Tizen::Base::String& result);
89 * Tizen::Uix::Speech::SpeechToText* __pStt;
92 * //Sample code for SpeechToTextSample.cpp
93 * #include "SpeechToTextSample.h"
95 * SpeechToTextSample::SpeechToTextSample(void)
100 * SpeechToTextSample::~SpeechToTextSample(void)
104 * void SpeechToTextSample::OnSpeechToTextInitialized(void)
107 * __pStt->SetLocale(Locale(LANGUAGE_ENG, COUNTRY_US));
109 * __pStt->SetSilenceDetectionEnabled(true);
112 * void SpeechToTextSample::OnSpeechToTextStatusChanged(Tizen::Uix::Speech::SpeechToTextStatus status)
117 * void SpeechToTextSample::OnSpeechToTextErrorOccurred(Tizen::Uix::Speech::SpeechToTextError error)
122 * void SpeechToTextSample::OnSpeechToTextCompleted(Tizen::Base::String& result)
127 * bool SpeechToTextSample::Initialize(void)
129 * result r = E_SUCCESS;
131 * __pStt = new SpeechToText();
133 * r = __pStt->Construct(*this);
136 * AppLog("Error code: %s", GetErrorMessage(r)):
140 * r = __pStt->Initialize();
143 * AppLog("Error code: %s", GetErrorMessage(r)):
149 * void SpeechToTextSample::Start(void)
151 * if (__pStt->GetCurrentStatus() == SPEECH_TO_TEXT_STATUS_READY)
159 class _OSP_EXPORT_ SpeechToText
160 : public Tizen::Base::Object
164 * The object is not fully constructed after this constructor is called. @n
165 * For full construction, the Construct() method must be called right after calling this constructor.
172 * This destructor overrides Tizen::Base::Object::~Object().
176 virtual ~SpeechToText(void);
179 * Initializes this instance of %SpeechToText with the specified @c listener.
183 * @return An error code
184 * @param[in] listener An instance of ISpeechToTextEventListener
185 * @exception E_SUCCESS The method is successful.
186 * @exception E_SYSTEM A system error has occurred.
187 * @exception E_OUT_OF_MEMORY The memory is insufficient.
189 result Construct(ISpeechToTextEventListener& listener);
192 * Initializes the Speech-To-Text service. @n
193 * This method is asynchronous. @n
194 * The ISpeechToTextEventListener::OnSpeechToTextInitialized() is invoked when the service has been initialized.
197 * @return An error code
198 * @exception E_SUCCESS The method is successful.
199 * @exception E_OUT_OF_MEMORY The memory is insufficient.
200 * @remarks This method must be called after Construct().
202 result Initialize(void);
205 * Starts recording the speech of a user and converts it to text.
209 * @return An error code
210 * @exception E_SUCCESS The method is successful.
211 * @exception E_SYSTEM A system error has occurred.
212 * @exception E_OUT_OF_MEMORY The memory is insufficient.
213 * @exception E_SERVICE_BUSY The recorder is busy.
214 * @exception E_INVALID_STATE This instance is not initialized as yet.
215 * @exception E_INVALID_OPERATION The current status should be @c SPEECH_TO_TEXT_STATUS_READY.
220 * Stops the recording and current Speech-To-Text service.
224 * @return An error code
225 * @exception E_SUCCESS The method is successful.
226 * @exception E_SYSTEM A system error has occurred.
227 * @exception E_OUT_OF_MEMORY The memory is insufficient.
228 * @exception E_INVALID_STATE This instance is not initialized as yet.
229 * @exception E_INVALID_OPERATION The current status should be @c SPEECH_TO_TEXT_STATUS_RECORDING.
234 * Cancels the in-progress recognition of the Speech-To-Text service.
238 * @return An error code
239 * @exception E_SUCCESS The method is successful.
240 * @exception E_SYSTEM A system error has occurred.
241 * @exception E_INVALID_STATE This instance is not initialized as yet.
242 * @exception E_INVALID_OPERATION The current status should be @c SPEECH_TO_TEXT_STATUS_RECORDING or @c SPEECH_TO_TEXT_STATUS_PROCESSING.
247 * Sets the locale for the Speech-To-Text service.
251 * @return An error code
252 * @param[in] locale The locale
253 * @exception E_SUCCESS The method is successful.
254 * @exception E_UNSUPPORTED_LOCALE This locale is not supported.
255 * @exception E_INVALID_STATE This instance is not initialized as yet.
256 * @see GetSupportedLocales()
258 result SetLocale(const Tizen::Locales::Locale& locale);
261 * Gets the current locale.
265 * @return A current locale
266 * @exception E_SUCCESS The method is successful.
267 * @exception E_INVALID_STATE This instance is not initialized as yet.
268 * @remarks The specific error code can be accessed using the GetLastResult() method.
270 Tizen::Locales::Locale GetLocale(void) const;
273 * Checks whether a locale is supported or not.
277 * @return @c true if the locale is available, @n
279 * @param[in] locale The locale
280 * @exception E_SUCCESS The method is successful.
281 * @exception E_INVALID_STATE This instance is not initialized as yet.
282 * @remarks The specific error code can be accessed using the GetLastResult() method.
284 bool IsLocaleSupported(const Tizen::Locales::Locale& locale) const;
287 * Gets the list of supported locales. @n
288 * Each list's item has a pointer of Tizen::Locales::Locale value.
292 * @return A list of locales
293 * @exception E_SUCCESS The method is successful.
294 * @exception E_INVALID_STATE This instance is not initialized as yet.
295 * @remarks The specific error code can be accessed using the GetLastResult() method.
297 const Tizen::Base::Collection::IList* GetSupportedLocales(void) const;
300 * Sets the grammar for %SpeechToText.
304 * @return An error code
305 * @param[in] grammar A grammar
306 * @exception E_SUCCESS The method is successful.
307 * @exception E_INVALID_STATE This instance is not initialized as yet.
309 result SetGrammar(SpeechToTextGrammar grammar);
312 * Gets the current grammar.
316 * @return The current grammar used by recognition
317 * @exception E_SUCCESS The method is successful.
318 * @exception E_INVALID_STATE This instance is not initialized as yet.
319 * @remarks The specific error code can be accessed using the GetLastResult() method.
321 SpeechToTextGrammar GetGrammar(void) const;
324 * Sets the silence detection enabled or disabled.
328 * @return An error code
329 * @param[in] enable Set to @c true to enable the silence detection, @n
331 * @exception E_SUCCESS The method is successful.
332 * @exception E_INVALID_STATE This instance is not initialized as yet.
334 result SetSilenceDetectionEnabled(bool enable);
337 * Checks whether the silence detection feature is enabled.
341 * @return @c true if the silence detection is enabled, @n
343 * @exception E_SUCCESS The method is successful.
344 * @exception E_INVALID_STATE This instance is not initialized as yet.
345 * @remarks The specific error code can be accessed using the GetLastResult() method.
347 bool IsSilenceDetectionEnabled(void) const;
350 * Gets the current status.
354 * @return current status
355 * @exception E_SUCCESS The method is successful.
356 * @exception E_INVALID_STATE This instance is not initialized as yet.
357 * @remarks The specific error code can be accessed using the GetLastResult() method.
359 SpeechToTextStatus GetCurrentStatus(void) const;
364 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
368 SpeechToText(const SpeechToText& rhs);
371 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
375 SpeechToText& operator =(const SpeechToText& rhs);
378 _SpeechToTextImpl* __pSpeechToTextImpl;
379 friend class _SpeechToTextImpl;
383 } } } // Tizen::Uix::Speech