Add functions to set credential
[platform/core/uifw/stt.git] / include / stt.h
1 /*
2  * Copyright (c) 2011-2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __STT_H__
18 #define __STT_H__
19
20 #include <tizen.h>
21
22 /**
23  * @file stt.h
24  */
25
26 /**
27 * @addtogroup CAPI_UIX_STT_MODULE
28 * @{
29 */
30
31 #ifdef __cplusplus
32 extern "C"
33 {
34 #endif
35
36 /**
37  * @brief Enumerations for error codes.
38  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
39 */
40 typedef enum {
41         STT_ERROR_NONE                  = TIZEN_ERROR_NONE,             /**< Successful */
42         STT_ERROR_OUT_OF_MEMORY         = TIZEN_ERROR_OUT_OF_MEMORY,    /**< Out of Memory */
43         STT_ERROR_IO_ERROR              = TIZEN_ERROR_IO_ERROR,         /**< I/O error */
44         STT_ERROR_INVALID_PARAMETER     = TIZEN_ERROR_INVALID_PARAMETER,/**< Invalid parameter */
45         STT_ERROR_TIMED_OUT             = TIZEN_ERROR_TIMED_OUT,        /**< No answer from the daemon */
46         STT_ERROR_RECORDER_BUSY         = TIZEN_ERROR_RESOURCE_BUSY,    /**< Device or resource busy */
47         STT_ERROR_OUT_OF_NETWORK        = TIZEN_ERROR_NETWORK_DOWN,     /**< Network is down */
48         STT_ERROR_PERMISSION_DENIED     = TIZEN_ERROR_PERMISSION_DENIED,/**< Permission denied */
49         STT_ERROR_NOT_SUPPORTED         = TIZEN_ERROR_NOT_SUPPORTED,    /**< STT NOT supported */
50         STT_ERROR_INVALID_STATE         = TIZEN_ERROR_STT | 0x01,       /**< Invalid state */
51         STT_ERROR_INVALID_LANGUAGE      = TIZEN_ERROR_STT | 0x02,       /**< Invalid language */
52         STT_ERROR_ENGINE_NOT_FOUND      = TIZEN_ERROR_STT | 0x03,       /**< No available engine  */
53         STT_ERROR_OPERATION_FAILED      = TIZEN_ERROR_STT | 0x04,       /**< Operation failed  */
54         STT_ERROR_NOT_SUPPORTED_FEATURE = TIZEN_ERROR_STT | 0x05        /**< Not supported feature of current engine */
55 } stt_error_e;
56
57 /**
58  * @brief Definition for free form dictation and default type.
59  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
60 */
61 #define STT_RECOGNITION_TYPE_FREE               "stt.recognition.type.FREE"
62
63 /**
64  * @brief Definition for continuous free dictation.
65  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
66 */
67 #define STT_RECOGNITION_TYPE_FREE_PARTIAL       "stt.recognition.type.FREE.PARTIAL"
68
69 /**
70  * @brief Definition for search.
71  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
72 */
73 #define STT_RECOGNITION_TYPE_SEARCH             "stt.recognition.type.SEARCH"
74
75 /**
76  * @brief Definition for web search.
77  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
78 */
79 #define STT_RECOGNITION_TYPE_WEB_SEARCH         "stt.recognition.type.WEB_SEARCH"
80
81 /**
82  * @brief Definition for map.
83  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
84 */
85 #define STT_RECOGNITION_TYPE_MAP                "stt.recognition.type.MAP"
86
87 /**
88  * @brief Definition for none message.
89  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
90 */
91 #define STT_RESULT_MESSAGE_NONE                 "stt.result.message.none"
92
93 /**
94  * @brief Definition for failed recognition because the speech started too soon.
95  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
96 */
97 #define STT_RESULT_MESSAGE_ERROR_TOO_SOON       "stt.result.message.error.too.soon"
98
99 /**
100  * @brief Definition for failed recognition because the speech is too short.
101  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
102 */
103 #define STT_RESULT_MESSAGE_ERROR_TOO_SHORT      "stt.result.message.error.too.short"
104
105 /**
106  * @brief Definition for failed recognition because the speech is too long.
107  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
108 */
109 #define STT_RESULT_MESSAGE_ERROR_TOO_LONG       "stt.result.message.error.too.long"
110
111 /**
112  * @brief Definition for failed recognition because the speech is too quiet to listen.
113  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
114 */
115 #define STT_RESULT_MESSAGE_ERROR_TOO_QUIET      "stt.result.message.error.too.quiet"
116
117 /**
118  * @brief Definition for failed recognition because the speech is too loud to listen.
119  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
120 */
121 #define STT_RESULT_MESSAGE_ERROR_TOO_LOUD       "stt.result.message.error.too.loud"
122
123 /**
124  * @brief Definition for failed recognition because the speech is too fast to listen.
125  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
126 */
127 #define STT_RESULT_MESSAGE_ERROR_TOO_FAST       "stt.result.message.error.too.fast"
128
129
130 /**
131  * @brief Enumeration for state.
132  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
133 */
134 typedef enum {
135         STT_STATE_CREATED       = 0,            /**< 'CREATED' state */
136         STT_STATE_READY         = 1,            /**< 'READY' state */
137         STT_STATE_RECORDING     = 2,            /**< 'RECORDING' state */
138         STT_STATE_PROCESSING    = 3             /**< 'PROCESSING' state*/
139 } stt_state_e;
140
141 /**
142  * @brief Enumeration for result event.
143  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
144 */
145 typedef enum {
146         STT_RESULT_EVENT_FINAL_RESULT = 0,      /**< Event when the recognition full or last result is ready  */
147         STT_RESULT_EVENT_PARTIAL_RESULT,        /**< Event when the recognition partial result is ready  */
148         STT_RESULT_EVENT_ERROR                  /**< Event when the recognition has failed */
149 } stt_result_event_e;
150
151 /**
152  * @brief Enumeration for result time callback event.
153  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
154 */
155 typedef enum {
156         STT_RESULT_TIME_EVENT_BEGINNING = 0,    /**< Event when the token is beginning type */
157         STT_RESULT_TIME_EVENT_MIDDLE = 1,       /**< Event when the token is middle type */
158         STT_RESULT_TIME_EVENT_END = 2           /**< Event when the token is end type */
159 } stt_result_time_event_e;
160
161 /**
162  * @brief Enumeration for silence detection type.
163  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
164 */
165 typedef enum {
166         STT_OPTION_SILENCE_DETECTION_FALSE = 0, /**< Silence detection type - False */
167         STT_OPTION_SILENCE_DETECTION_TRUE = 1,  /**< Silence detection type - True */
168         STT_OPTION_SILENCE_DETECTION_AUTO = 2   /**< Silence detection type - Auto */
169 } stt_option_silence_detection_e;
170
171 /**
172  * @brief A structure of STT handler.
173  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
174 */
175 typedef struct stt_s *stt_h;
176
177 /**
178  * @brief Called to get the engine information.
179  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
180  *
181  * @param[in] engine_id Engine id
182  * @param[in] engine_name Engine name
183  * @param[in] user_data User data passed from the stt_setting_foreach_supported_engines()
184  *
185  * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop
186  * @pre stt_foreach_supported_engines() will invoke this callback.
187  *
188  * @see stt_foreach_supported_engines()
189 */
190 typedef bool(*stt_supported_engine_cb)(stt_h stt, const char* engine_id, const char* engine_name, void* user_data);
191
192 /**
193  * @brief Called when STT gets the recognition result from the engine.
194  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
195  *
196  * @remarks After stt_stop() is called, silence is detected from recording, or partial result is occured,
197  *      this function is called.
198  *
199  * @param[in] stt The STT handle
200  * @param[in] event The result event
201  * @param[in] data Result texts
202  * @param[in] data_count Result text count
203  * @param[in] msg Engine message (e.g. #STT_RESULT_MESSAGE_NONE, #STT_RESULT_MESSAGE_ERROR_TOO_SHORT)
204  * @param[in] user_data The user data passed from the callback registration function
205  *
206  * @pre stt_stop() will invoke this callback if you register it using stt_set_result_cb().
207  * @post If this function is called and event is #STT_RESULT_EVENT_FINAL_RESULT, the STT state will be #STT_STATE_READY.
208  *
209  * @see stt_stop()
210  * @see stt_set_recognition_result_cb()
211  * @see stt_unset_recognition_result_cb()
212 */
213 typedef void (*stt_recognition_result_cb)(stt_h stt, stt_result_event_e event, const char** data, int data_count,
214                                           const char* msg, void *user_data);
215
216 /**
217  * @brief Called when STT get the result time stamp in free partial type.
218  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
219  *
220  * @param[in] stt The STT handle
221  * @param[in] index The result index
222  * @param[in] event The token event
223  * @param[in] text The result text
224  * @param[in] start_time The start time of result text
225  * @param[in] end_time The end time of result text
226  * @param[in] user_data The user data passed from the foreach function
227  *
228  * @return @c true to continue with the next iteration of the loop \n @c false to break out of the loop
229  *
230  * @pre stt_recognition_result_cb() should be called.
231  *
232  * @see stt_recognition_result_cb()
233 */
234 typedef bool (*stt_result_time_cb)(stt_h stt, int index, stt_result_time_event_e event, const char* text,
235                                    long start_time, long end_time, void* user_data);
236
237 /**
238  * @brief Called when the state of STT is changed.
239  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
240  *
241  * @param[in] stt The STT handle
242  * @param[in] previous A previous state
243  * @param[in] current A current state
244  * @param[in] user_data The user data passed from the callback registration function
245  *
246  * @pre An application registers this callback using stt_set_state_changed_cb() to detect changing state.
247  *
248  * @see stt_set_state_changed_cb()
249  * @see stt_unset_state_changed_cb()
250 */
251 typedef void (*stt_state_changed_cb)(stt_h stt, stt_state_e previous, stt_state_e current, void* user_data);
252
253 /**
254  * @brief Called when an error occurs.
255  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
256  *
257  * @param[in] stt The STT handle
258  * @param[in] reason The error type (e.g. #STT_ERROR_OUT_OF_NETWORK, #STT_ERROR_IO_ERROR)
259  * @param[in] user_data The user data passed from the callback registration function
260  *
261  * @pre An application registers this callback using stt_set_error_cb() to detect error.
262  *
263  * @see stt_set_error_cb()
264  * @see stt_unset_error_cb()
265 */
266 typedef void (*stt_error_cb)(stt_h stt, stt_error_e reason, void *user_data);
267
268 /**
269  * @brief Called to retrieve the supported languages.
270  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
271  * @remarks The language is specified as an ISO 3166 alpha-2 two letter country-code followed by ISO 639-1 for the two-letter language code. For example, "ko_KR" for Korean, "en_US" for American English.
272  *
273  * @param[in] stt The STT handle
274  * @param[in] language The language
275  * @param[in] user_data The user data passed from the foreach function
276  *
277  * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop
278  * @pre stt_foreach_supported_languages() will invoke this callback.
279  *
280  * @see stt_foreach_supported_languages()
281 */
282 typedef bool (*stt_supported_language_cb)(stt_h stt, const char* language, void* user_data);
283
284 /**
285  * @brief Called when the default language is changed.
286  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
287  *
288  * @param[in] stt The STT handle
289  * @param[in] previous_language A previous language
290  * @param[in] current_language A current language
291  * @param[in] user_data The user data passed from the callback registration function
292  *
293  * @see stt_set_default_language_changed_cb()
294 */
295 typedef void (*stt_default_language_changed_cb)(stt_h stt, const char* previous_language,
296                                                 const char* current_language, void* user_data);
297
298 /**
299  * @brief Called when the engine is changed.
300  * @since_tizen 3.0
301  *
302  * @param[in] stt The STT handle
303  * @param[in] engine_id Engine id
304  * @param[in] language The default language
305  * @param[in] support_silence support silence detection
306  * @param[in] need_credential necessity of credential
307  * @param[in] user_data The user data passed from the callback registration function
308  *
309  * @see stt_set_engine_changed_cb()
310 */
311 typedef bool (*stt_engine_changed_cb)(stt_h stt, const char* engine_id, const char* language,
312                                                 bool support_silence, bool need_credential, void* user_data);
313
314 /**
315  * @brief Creates a STT handle.
316  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
317  * @privlevel public
318  * @privilege %http://tizen.org/privilege/recorder
319  *
320  * @remarks If the function succeeds, @a stt handle must be released with stt_destroy().
321  *
322  * @param[out] stt The STT handle
323  *
324  * @return 0 on success, otherwise a negative error value
325  * @retval #STT_ERROR_NONE Successful
326  * @retval #STT_ERROR_OUT_OF_MEMORY Out of memory
327  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
328  * @retval #STT_ERROR_OPERATION_FAILED Operation failure
329  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
330  *
331  * @post If this function is called, the STT state will be #STT_STATE_CREATED.
332  *
333  * @see stt_destroy()
334 */
335 int stt_create(stt_h* stt);
336
337 /**
338  * @brief Destroys a STT handle.
339  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
340  * @privlevel public
341  * @privilege %http://tizen.org/privilege/recorder
342  *
343  * @param[in] stt The STT handle
344  *
345  * @return 0 on success, otherwise a negative error value
346  * @retval #STT_ERROR_NONE Successful
347  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
348  * @retval #STT_ERROR_OPERATION_FAILED Operation failure
349  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
350  *
351  * @see stt_create()
352 */
353 int stt_destroy(stt_h stt);
354
355 /**
356  * @brief Retrieves supported engine information using a callback function.
357  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
358  * @privlevel public
359  * @privilege %http://tizen.org/privilege/recorder
360  *
361  * @param[in] stt The STT handle
362  * @param[in] callback The callback function to invoke
363  * @param[in] user_data The user data to be passed to the callback function
364  *
365  * @return 0 on success, otherwise a negative error value
366  * @retval #STT_ERROR_NONE Success
367  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
368  * @retval #STT_ERROR_INVALID_STATE STT Not initialized
369  * @retval #STT_ERROR_OPERATION_FAILED Operation failure
370  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
371  *
372  * @pre The state should be #STT_STATE_CREATED.
373  * @post This function invokes stt_supported_engine_cb() repeatedly for getting engine information.
374  *
375  * @see stt_supported_engine_cb()
376 */
377 int stt_foreach_supported_engines(stt_h stt, stt_supported_engine_cb callback, void* user_data);
378
379 /**
380  * @brief Gets the current engine id.
381  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
382  * @privlevel public
383  * @privilege %http://tizen.org/privilege/recorder
384  *
385  * @remarks If the function is success, @a engine_id must be released using free().
386  *
387  * @param[in] stt The STT handle
388  * @param[out] engine_id Engine id
389  *
390  * @return 0 on success, otherwise a negative error value
391  * @retval #STT_ERROR_NONE Success
392  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
393  * @retval #STT_ERROR_INVALID_STATE STT Not initialized
394  * @retval #STT_ERROR_OPERATION_FAILED Operation failure
395  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
396  *
397  * @pre The state should be #STT_STATE_CREATED.
398  *
399  * @see stt_set_engine()
400 */
401 int stt_get_engine(stt_h stt, char** engine_id);
402
403 /**
404  * @brief Sets the engine id.
405  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
406  * @privlevel public
407  * @privilege %http://tizen.org/privilege/recorder
408  *
409  * @param[in] stt The STT handle
410  * @param[in] engine_id Engine id
411  *
412  * @return 0 on success, otherwise a negative error value
413  * @retval #STT_ERROR_NONE Success
414  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
415  * @retval #STT_ERROR_INVALID_STATE STT Not initialized
416  * @retval #STT_ERROR_OPERATION_FAILED Operation failure
417  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
418  *
419  * @pre The state should be #STT_STATE_CREATED.
420  *
421  * @see stt_get_engine()
422 */
423 int stt_set_engine(stt_h stt, const char* engine_id);
424
425 /**
426  * @brief Sets the app credential.
427  * @since_tizen 3.0
428  * @privlevel public
429  * @privilege %http://tizen.org/privilege/recorder
430  *
431  * @param[in] stt The STT handle
432  * @param[in] credential The app credential
433  *
434  * @return 0 on success, otherwise a negative error value
435  * @retval #STT_ERROR_NONE Success
436  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
437  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
438  *
439  * @pre The state should be #STT_STATE_CREATED or #STT_STATE_READY.
440  *
441  * @see stt_start()
442 */
443
444 int stt_set_credential(stt_h stt, const char* credential);
445
446 /**
447  * @brief Connects the daemon asynchronously.
448  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
449  * @privlevel public
450  * @privilege %http://tizen.org/privilege/recorder
451  *
452  * @param[in] stt The STT handle
453  *
454  * @return 0 on success, otherwise a negative error value
455  * @retval #STT_ERROR_NONE Successful
456  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
457  * @retval #STT_ERROR_INVALID_STATE Invalid state
458  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
459  *
460  * @pre The state should be #STT_STATE_CREATED.
461  * @post If this function is successful, the STT state will be #STT_STATE_READY. \n
462  *      If this function is failed, the error callback is called. (e.g. #STT_ERROR_ENGINE_NOT_FOUND)
463  *
464  * @see stt_unprepare()
465 */
466 int stt_prepare(stt_h stt);
467
468 /**
469  * @brief Disconnects the daemon.
470  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
471  * @privlevel public
472  * @privilege %http://tizen.org/privilege/recorder
473  *
474  * @param[in] stt The STT handle
475  *
476  * @return 0 on success, otherwise a negative error value
477  * @retval #STT_ERROR_NONE Successful
478  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
479  * @retval #STT_ERROR_INVALID_STATE Invalid state
480  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
481  *
482  * @pre The state should be #STT_STATE_READY.
483  * @post If this function is called, the STT state will be #STT_STATE_CREATED.
484  *
485  * @see stt_prepare()
486 */
487 int stt_unprepare(stt_h stt);
488
489 /**
490  * @brief Retrieves all supported languages of current engine using callback function.
491  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
492  * @privlevel public
493  * @privilege %http://tizen.org/privilege/recorder
494  *
495  * @param[in] stt The STT handle
496  * @param[in] callback The callback function to invoke
497  * @param[in] user_data The user data to be passed to the callback function
498  *
499  * @return 0 on success, otherwise a negative error value
500  * @retval #STT_ERROR_NONE Successful
501  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
502  * @retval #STT_ERROR_OPERATION_FAILED Operation failure
503  * @retval #STT_ERROR_ENGINE_NOT_FOUND No available engine
504  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
505  *
506  * @post This function invokes stt_supported_language_cb() repeatedly for getting languages.
507  *
508  * @see stt_supported_language_cb()
509  * @see stt_get_default_language()
510 */
511 int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callback, void* user_data);
512
513 /**
514  * @brief Gets the default language set by the user.
515  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
516  * @privlevel public
517  * @privilege %http://tizen.org/privilege/recorder
518  * @remarks The language is specified as an ISO 3166 alpha-2 two letter country-code followed by ISO 639-1 for the two-letter language code. \n
519  * For example, "ko_KR" for Korean, "en_US" for American English. \n
520  * If the function succeeds, @a language must be released using free() when it is no longer required.
521  *
522  * @param[in] stt The STT handle
523  * @param[out] language The language
524  *
525  * @return 0 on success, otherwise a negative error value
526  * @retval #STT_ERROR_NONE Successful
527  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
528  * @retval #STT_ERROR_OPERATION_FAILED Operation failure
529  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
530  *
531  * @see stt_foreach_supported_languages()
532 */
533 int stt_get_default_language(stt_h stt, char** language);
534
535 /**
536  * @brief Gets the current STT state.
537  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
538  * @privlevel public
539  * @privilege %http://tizen.org/privilege/recorder
540  *
541  * @param[in] stt The STT handle
542  * @param[out] state The current STT state
543  *
544  * @return 0 on success, otherwise a negative error value
545  * @retval #STT_ERROR_NONE Successful
546  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
547  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
548  *
549  * @see stt_start()
550  * @see stt_stop()
551  * @see stt_cancel()
552  * @see stt_state_changed_cb()
553 */
554 int stt_get_state(stt_h stt, stt_state_e* state);
555
556 /**
557  * @brief Gets the current error message.
558  * @since_tizen 3.0
559  * @privlevel public
560  * @privilege %http://tizen.org/privilege/recorder
561  * @remarks This function should be called during an stt error callback. If not, the error as operation failure will be returned. \n
562  * If the function succeeds, @a err_msg must be released using free() when it is no longer required.
563  *
564  * @param[in] stt The STT handle
565  * @param[out] err_msg The current error message
566  *
567  * @return 0 on success, otherwise a negative error value
568  * @retval #STT_ERROR_NONE Successful
569  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
570  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
571  * @retval #STT_ERROR_OPERATION_FAILED Operation failure
572  *
573  * @see stt_set_error_cb()
574  * @see stt_unset_error_cb()
575 */
576 int stt_get_error_message(stt_h stt, char** err_msg);
577
578 /**
579  * @brief Checks whether the recognition type is supported.
580  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
581  * @privlevel public
582  * @privilege %http://tizen.org/privilege/recorder
583  *
584  * @param[in] stt The STT handle
585  * @param[in] type The type for recognition (e.g. #STT_RECOGNITION_TYPE_FREE, #STT_RECOGNITION_TYPE_FREE_PARTIAL)
586  * @param[out] support The result status @c true = supported, @c false = not supported
587  *
588  * @return 0 on success, otherwise a negative error value
589  * @retval #STT_ERROR_NONE Successful
590  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
591  * @retval #STT_ERROR_OPERATION_FAILED Operation failure
592  * @retval #STT_ERROR_INVALID_STATE Invalid state
593  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
594  *
595  * @pre The state should be #STT_STATE_READY.
596 */
597 int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support);
598
599 /**
600  * @brief Sets the silence detection.
601  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
602  * @privlevel public
603  * @privilege %http://tizen.org/privilege/recorder
604  *
605  * @param[in] stt The STT handle
606  * @param[in] type The option type
607  *
608  * @return 0 on success, otherwise a negative error value
609  * @retval #STT_ERROR_NONE Successful
610  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
611  * @retval #STT_ERROR_INVALID_STATE Invalid state
612  * @retval #STT_ERROR_NOT_SUPPORTED_FEATURE Not supported feature of current engine
613  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
614  *
615  * @pre The state should be #STT_STATE_READY.
616 */
617 int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type);
618
619 /**
620  * @brief Sets the sound to start recording.
621  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
622  * @privlevel public
623  * @privilege %http://tizen.org/privilege/recorder
624  *
625  * @remarks Sound file type should be wav type.
626  *
627  * @param[in] stt The STT handle
628  * @param[in] filename The sound file path
629  *
630  * @return 0 on success, otherwise a negative error value
631  * @retval #STT_ERROR_NONE Successful
632  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
633  * @retval #STT_ERROR_INVALID_STATE Invalid state
634  * @retval #STT_ERROR_OPERATION_FAILED Operation failure
635  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
636  *
637  * @pre The state should be #STT_STATE_READY.
638 */
639 int stt_set_start_sound(stt_h stt, const char* filename);
640
641 /**
642  * @brief Unsets the sound to start recording.
643  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
644  * @privlevel public
645  * @privilege %http://tizen.org/privilege/recorder
646  *
647  * @param[in] stt The STT handle
648  *
649  * @return 0 on success, otherwise a negative error value
650  * @retval #STT_ERROR_NONE Successful
651  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
652  * @retval #STT_ERROR_INVALID_STATE Invalid state
653  * @retval #STT_ERROR_OPERATION_FAILED Operation failure
654  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
655  *
656  * @pre The state should be #STT_STATE_READY.
657 */
658 int stt_unset_start_sound(stt_h stt);
659
660 /**
661  * @brief Sets the sound to stop recording.
662  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
663  * @privlevel public
664  * @privilege %http://tizen.org/privilege/recorder
665  *
666  * @remarks Sound file type should be wav type.
667  *
668  * @param[in] stt The STT handle
669  * @param[in] filename The sound file path
670  *
671  * @return 0 on success, otherwise a negative error value
672  * @retval #STT_ERROR_NONE Successful
673  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
674  * @retval #STT_ERROR_INVALID_STATE Invalid state
675  * @retval #STT_ERROR_OPERATION_FAILED Operation failure
676  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
677  *
678  * @pre The state should be #STT_STATE_READY.
679 */
680 int stt_set_stop_sound(stt_h stt, const char* filename);
681
682 /**
683  * @brief Unsets the sound to stop recording.
684  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
685  * @privlevel public
686  * @privilege %http://tizen.org/privilege/recorder
687  *
688  * @param[in] stt The STT handle
689  *
690  * @return 0 on success, otherwise a negative error value
691  * @retval #STT_ERROR_NONE Successful
692  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
693  * @retval #STT_ERROR_INVALID_STATE Invalid state
694  * @retval #STT_ERROR_OPERATION_FAILED Operation failure
695  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
696  *
697  * @pre The state should be #STT_STATE_READY.
698 */
699 int stt_unset_stop_sound(stt_h stt);
700
701 /**
702  * @brief Starts recording and recognition asynchronously.
703  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
704  * @privlevel public
705  * @privilege %http://tizen.org/privilege/recorder
706  *
707  * @remarks This function starts recording in the daemon and sending recording data to engine. \n
708  * This work continues until stt_stop(), stt_cancel() or silence detected by engine.
709  *
710  * @param[in] stt The STT handle
711  * @param[in] language The language selected from stt_foreach_supported_languages()
712  * @param[in] type The type for recognition (e.g. #STT_RECOGNITION_TYPE_FREE, #STT_RECOGNITION_TYPE_FREE_PARTIAL)
713  *
714  * @return 0 on success, otherwise a negative error value
715  * @retval #STT_ERROR_NONE Successful
716  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
717  * @retval #STT_ERROR_INVALID_STATE Invalid state
718  * @retval #STT_ERROR_OPERATION_FAILED Operation failure
719  * @retval #STT_ERROR_RECORDER_BUSY Recorder busy
720  * @retval #STT_ERROR_INVALID_LANGUAGE Invalid language
721  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
722  *
723  * @pre The state should be #STT_STATE_READY.
724  * @post It will invoke stt_state_changed_cb(), if you register a callback with stt_state_changed_cb(). \n
725  * If this function succeeds, the STT state will be #STT_STATE_RECORDING.
726  *
727  * @see stt_stop()
728  * @see stt_cancel()
729  * @see stt_state_changed_cb()
730 */
731 int stt_start(stt_h stt, const char* language, const char* type);
732
733 /**
734  * @brief Finishes the recording and starts recognition processing in engine asynchronously.
735  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
736  * @privlevel public
737  * @privilege %http://tizen.org/privilege/recorder
738  *
739  * @param[in] stt The STT handle
740  *
741  * @return 0 on success, otherwise a negative error value
742  * @retval #STT_ERROR_NONE Successful
743  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
744  * @retval #STT_ERROR_INVALID_STATE Invalid state
745  * @retval #STT_ERROR_OPERATION_FAILED Operation failure
746  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
747  *
748  * @pre The state should be #STT_STATE_RECORDING.
749  * @post It will invoke stt_state_changed_cb(), if you register a callback with stt_state_changed_cb(). \n
750  * If this function succeeds, the STT state will be #STT_STATE_PROCESSING. \n
751  * After processing of engine, stt_result_cb() is called.
752  *
753  * @see stt_start()
754  * @see stt_cancel()
755  * @see stt_state_changed_cb()
756 */
757 int stt_stop(stt_h stt);
758
759 /**
760  * @brief Cancels processing recognition and recording asynchronously.
761  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
762  * @privlevel public
763  * @privilege %http://tizen.org/privilege/recorder
764  *
765  * @remarks This function cancels recording and engine cancels recognition processing. \n
766  * After successful cancel, stt_state_changed_cb() is called otherwise if error is occurred, stt_error_cb() is called.
767  *
768  * @param[in] stt The STT handle
769  *
770  * @return 0 on success, otherwise a negative error value
771  * @retval #STT_ERROR_NONE Successful
772  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
773  * @retval #STT_ERROR_INVALID_STATE Invalid state
774  * @retval #STT_ERROR_OPERATION_FAILED Operation failure
775  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
776  *
777  * @pre The state should be #STT_STATE_RECORDING or #STT_STATE_PROCESSING.
778  * @post It will invoke stt_state_changed_cb(), if you register a callback with stt_state_changed_cb(). \n
779  * If this function succeeds, the STT state will be #STT_STATE_READY.
780  *
781  * @see stt_start()
782  * @see stt_stop()
783  * @see stt_state_changed_cb()
784 */
785 int stt_cancel(stt_h stt);
786
787 /**
788  * @brief Gets the microphone volume during recording.
789  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
790  * @privlevel public
791  * @privilege %http://tizen.org/privilege/recorder
792  *
793  * @param[in] stt The STT handle
794  * @param[out] volume Recording volume
795  *
796  * @return 0 on success, otherwise a negative error value
797  * @retval #STT_ERROR_NONE Successful
798  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
799  * @retval #STT_ERROR_INVALID_STATE Invalid state
800  * @retval #STT_ERROR_OPERATION_FAILED Operation failure
801  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
802  *
803  * @pre The state should be #STT_STATE_RECORDING.
804  *
805  * @see stt_start()
806 */
807 int stt_get_recording_volume(stt_h stt, float* volume);
808
809 /**
810  * @brief Retrieves the time stamp of the current recognition result using the callback function.
811  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
812  * @privlevel public
813  * @privilege %http://tizen.org/privilege/recorder
814  *
815  * @remarks This function should be called in stt_recognition_result_cb().
816  *      After stt_recognition_result_cb(), result data is NOT valid.
817  *
818  * @param[in] stt The STT handle
819  * @param[in] callback The callback function to invoke
820  * @param[in] user_data The user data to be passed to the callback function
821  *
822  * @return 0 on success, otherwise a negative error value
823  * @retval #STT_ERROR_NONE Successful
824  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
825  * @retval #STT_ERROR_OPERATION_FAILED Operation failure
826  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
827  *
828  * @pre This function should be called in stt_recognition_result_cb().
829  * @post This function invokes stt_result_time_cb() repeatedly for getting time information.
830  *
831  * @see stt_result_time_cb()
832  * @see stt_recognition_result_cb()
833 */
834 int stt_foreach_detailed_result(stt_h stt, stt_result_time_cb callback, void* user_data);
835
836 /**
837  * @brief Registers a callback function to get the recognition result.
838  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
839  * @privlevel public
840  * @privilege %http://tizen.org/privilege/recorder
841  *
842  * @param[in] stt The STT handle
843  * @param[in] callback The callback function to register
844  * @param[in] user_data The user data to be passed to the callback function
845  *
846  * @return 0 on success, otherwise a negative error value
847  * @retval #STT_ERROR_NONE Successful
848  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
849  * @retval #STT_ERROR_INVALID_STATE Invalid state
850  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
851  *
852  * @pre The state should be #STT_STATE_CREATED.
853  *
854  * @see stt_recognition_result_cb()
855  * @see stt_unset_recognition_result_cb()
856 */
857 int stt_set_recognition_result_cb(stt_h stt, stt_recognition_result_cb callback, void* user_data);
858
859 /**
860  * @brief Unregisters the callback function.
861  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
862  * @privlevel public
863  * @privilege %http://tizen.org/privilege/recorder
864  *
865  * @param[in] stt The STT handle
866  *
867  * @return 0 on success, otherwise a negative error value
868  * @retval #STT_ERROR_NONE Successful
869  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
870  * @retval #STT_ERROR_INVALID_STATE Invalid state
871  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
872  *
873  * @pre The state should be #STT_STATE_CREATED.
874  *
875  * @see stt_set_recognition_result_cb()
876 */
877 int stt_unset_recognition_result_cb(stt_h stt);
878
879 /**
880  * @brief Registers a callback function to be called when STT state changes.
881  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
882  * @privlevel public
883  * @privilege %http://tizen.org/privilege/recorder
884  *
885  * @param[in] stt The STT handle
886  * @param[in] callback The callback function to register
887  * @param[in] user_data The user data to be passed to the callback function
888  *
889  * @return 0 on success, otherwise a negative error value
890  * @retval #STT_ERROR_NONE Successful
891  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
892  * @retval #STT_ERROR_INVALID_STATE Invalid state
893  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
894  *
895  * @pre The state should be #STT_STATE_CREATED.
896  *
897  * @see stt_state_changed_cb()
898  * @see stt_unset_state_changed_cb()
899 */
900 int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* user_data);
901
902 /**
903  * @brief Unregisters the callback function.
904  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
905  * @privlevel public
906  * @privilege %http://tizen.org/privilege/recorder
907  *
908  * @param[in] stt The STT handle
909  *
910  * @return 0 on success, otherwise a negative error value
911  * @retval #STT_ERROR_NONE Successful
912  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
913  * @retval #STT_ERROR_INVALID_STATE Invalid state
914  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
915  *
916  * @pre The state should be #STT_STATE_CREATED.
917  *
918  * @see stt_set_state_changed_cb()
919 */
920 int stt_unset_state_changed_cb(stt_h stt);
921
922 /**
923  * @brief Registers a callback function to be called when an error occurred.
924  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
925  * @privlevel public
926  * @privilege %http://tizen.org/privilege/recorder
927  *
928  * @param[in] stt The STT handle
929  * @param[in] callback The callback function to register
930  * @param[in] user_data The user data to be passed to the callback function
931  *
932  * @return 0 on success, otherwise a negative error value
933  * @retval #STT_ERROR_NONE Successful
934  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
935  * @retval #STT_ERROR_INVALID_STATE Invalid state
936  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
937  *
938  * @pre The state should be #STT_STATE_CREATED.
939  *
940  * @see stt_error_cb()
941  * @see stt_unset_error_cb()
942 */
943 int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data);
944
945 /**
946  * @brief Unregisters the callback function.
947  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
948  * @privlevel public
949  * @privilege %http://tizen.org/privilege/recorder
950  *
951  * @param[in] stt The STT handle
952  *
953  * @return 0 on success, otherwise a negative error value
954  * @retval #STT_ERROR_NONE Successful
955  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
956  * @retval #STT_ERROR_INVALID_STATE Invalid state
957  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
958  *
959  * @pre The state should be #STT_STATE_CREATED.
960  *
961  * @see stt_set_error_cb()
962 */
963 int stt_unset_error_cb(stt_h stt);
964
965 /**
966  * @brief Registers a callback function to detect the default language change.
967  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
968  * @privlevel public
969  * @privilege %http://tizen.org/privilege/recorder
970  *
971  * @param[in] stt The STT handle
972  * @param[in] callback The callback function to register
973  * @param[in] user_data The user data to be passed to the callback function
974  *
975  * @return 0 on success, otherwise a negative error value
976  * @retval #STT_ERROR_NONE Successful
977  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
978  * @retval #STT_ERROR_INVALID_STATE Invalid state
979  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
980  *
981  * @pre The state should be #STT_STATE_CREATED.
982  *
983  * @see stt_default_language_changed_cb()
984  * @see stt_unset_default_language_changed_cb()
985 */
986 int stt_set_default_language_changed_cb(stt_h stt, stt_default_language_changed_cb callback, void* user_data);
987
988 /**
989  * @brief Unregisters the callback function.
990  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
991  * @privlevel public
992  * @privilege %http://tizen.org/privilege/recorder
993  *
994  * @param[in] stt The STT handle
995  *
996  * @return 0 on success, otherwise a negative error value
997  * @retval #STT_ERROR_NONE Successful
998  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
999  * @retval #STT_ERROR_INVALID_STATE Invalid state
1000  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
1001  *
1002  * @pre The state should be #STT_STATE_CREATED.
1003  *
1004  * @see stt_set_default_language_changed_cb()
1005 */
1006 int stt_unset_default_language_changed_cb(stt_h stt);
1007
1008 #ifdef __cplusplus
1009 }
1010 #endif
1011
1012 /**
1013  * @}@}
1014  */
1015
1016 #endif /* __STT_H__ */
1017