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