2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 * @addtogroup CAPI_UIX_STT_MODULE
34 * @brief Enumerations of error codes.
37 STT_ERROR_NONE = 0, /**< Successful */
38 STT_ERROR_OUT_OF_MEMORY = -ENOMEM, /**< Out of Memory */
39 STT_ERROR_IO_ERROR = -EIO, /**< I/O error */
40 STT_ERROR_INVALID_PARAMETER = -EINVAL, /**< Invalid parameter */
41 STT_ERROR_TIMED_OUT = -ETIMEDOUT, /**< No answer from the daemon */
42 STT_ERROR_RECORDER_BUSY = -EBUSY, /**< Busy recorder */
43 STT_ERROR_OUT_OF_NETWORK = -ENETDOWN, /**< Out of network */
44 STT_ERROR_INVALID_STATE = -0x0100000 | 0x31, /**< Invalid state */
45 STT_ERROR_INVALID_LANGUAGE = -0x0100000 | 0x32, /**< Invalid language */
46 STT_ERROR_ENGINE_NOT_FOUND = -0x0100000 | 0x33, /**< No available engine */
47 STT_ERROR_OPERATION_FAILED = -0x0100000 | 0x34, /**< Operation failed */
48 STT_ERROR_NOT_SUPPORTED_FEATURE = -0x0100000 | 0x35 /**< Not supported feature of current engine */
52 * @brief Recognition type : free form dictation or default type.
54 #define STT_RECOGNITION_TYPE_FREE "stt.recognition.type.FREE"
57 * @brief Recognition type : web search.
59 #define STT_RECOGNITION_TYPE_WEB_SEARCH "stt.recognition.type.WEB_SEARCH"
62 * @brief Result message : None message
64 #define STT_RESULT_MESSAGE_NONE "stt.result.message.none"
67 * @brief Result warning message : The speech has started too soon
69 #define STT_RESULT_MESSAGE_WARNING_TOO_SOON "stt.result.message.warning.too.soon"
72 * @brief Result warning message : The speech is too short
74 #define STT_RESULT_MESSAGE_WARNING_TOO_SHORT "stt.result.message.warning.too.short"
77 * @brief Result warning message : The speech is too long
79 #define STT_RESULT_MESSAGE_WARNING_TOO_LONG "stt.result.message.warning.too.long"
82 * @brief Result warning message : The speech is too quiet to listen
84 #define STT_RESULT_MESSAGE_WARNING_TOO_QUIET "stt.result.message.warning.too.quiet"
87 * @brief Result warning message : The speech is too loud to listen
89 #define STT_RESULT_MESSAGE_WARNING_TOO_LOUD "stt.result.message.warning.too.loud"
92 * @brief Result warning message : The speech is too fast to listen
94 #define STT_RESULT_MESSAGE_WARNING_TOO_FAST "stt.result.message.warning.too.fast"
97 * @brief Result error message : Recognition was failed because the speech started too soon
99 #define STT_RESULT_MESSAGE_ERROR_TOO_SOON "stt.result.message.error.too.soon"
102 * @brief Result error message : Recognition was failed because the speech started too short
104 #define STT_RESULT_MESSAGE_ERROR_TOO_SHORT "stt.result.message.error.too.short"
107 * @brief Result error message : Recognition was failed because the speech started too long
109 #define STT_RESULT_MESSAGE_ERROR_TOO_LONG "stt.result.message.error.too.long"
112 * @brief Result error message : Recognition was failed because the speech started too quiet to listen
114 #define STT_RESULT_MESSAGE_ERROR_TOO_QUIET "stt.result.message.error.too.quiet"
117 * @brief Result error message : Recognition was failed because the speech started too loud to listen
119 #define STT_RESULT_MESSAGE_ERROR_TOO_LOUD "stt.result.message.error.too.loud"
122 * @brief Result error message : Recognition was failed because the speech started too fast to listen
124 #define STT_RESULT_MESSAGE_ERROR_TOO_FAST "stt.result.message.error.too.fast"
128 * @brief Enumerations of state.
131 STT_STATE_CREATED = 0, /**< 'CREATED' state */
132 STT_STATE_READY, /**< 'READY' state */
133 STT_STATE_RECORDING, /**< 'RECORDING' state */
134 STT_STATE_PROCESSING /**< 'PROCESSING' state*/
138 * @brief Enumerations of profanity type.
141 STT_OPTION_PROFANITY_FALSE = 0, /**< Profanity type - False */
142 STT_OPTION_PROFANITY_TRUE = 1, /**< Profanity type - True */
143 STT_OPTION_PROFANITY_AUTO = 2 /**< Profanity type - Auto */
144 }stt_option_profanity_e;
147 * @brief Enumerations of punctuation type.
150 STT_OPTION_PUNCTUATION_FALSE = 0, /**< Punctuation type - False */
151 STT_OPTION_PUNCTUATION_TRUE = 1, /**< Punctuation type - True */
152 STT_OPTION_PUNCTUATION_AUTO = 2 /**< Punctuation type - Auto */
153 }stt_option_punctuation_e;
156 * @brief Enumerations of silence detection type.
159 STT_OPTION_SILENCE_DETECTION_FALSE = 0, /**< Silence detection type - False */
160 STT_OPTION_SILENCE_DETECTION_TRUE = 1, /**< Silence detection type - True */
161 STT_OPTION_SILENCE_DETECTION_AUTO = 2 /**< Silence detection type - Auto */
162 }stt_option_silence_detection_e;
165 * @brief A structure of handle for STT
167 typedef struct stt_s *stt_h;
170 * @brief Called when STT gets the recognition result from engine after the application call stt_stop().
172 * @remark If results of recognition is valid after stt_stop() is called or silence is detected from recording,
173 * this function is called.
175 * @param[in] stt The handle for STT
176 * @param[in] type Recognition type (e.g. #STT_RECOGNITION_TYPE_FREE, #STT_RECOGNITION_TYPE_WEB_SEARCH)
177 * @param[in] data Result texts
178 * @param[in] data_count Result text count
179 * @param[in] msg Engine message (e.g. #STT_RESULT_MESSAGE_WARNING_TOO_SOON, #STT_RESULT_MESSAGE_ERROR_TOO_SHORT)
180 * @param[in] user_data The user data passed from the callback registration function
182 * @pre stt_stop() will invoke this callback if you register it using stt_set_result_cb().
183 * @post If this function is called, the STT state will be #STT_STATE_READY.
186 * @see stt_set_result_cb()
187 * @see stt_unset_result_cb()
189 typedef void (*stt_result_cb)(stt_h stt, const char* type, const char** data, int data_count, const char* msg, void *user_data);
192 * @brief Called when STT gets recognition the partial result from engine after the application calls stt_start().
194 * @remark If a current engine supports partial result of recognition, this function can be called.
196 * @param[in] stt The handle for STT
197 * @param[in] data Result data
198 * @param[in] user_data The user data passed from the callback registration function
200 * @pre stt_start() will invoke this callback if you register it using stt_set_partial_result_cb().
203 * @see stt_set_partial_result_cb()
204 * @see stt_unset_partial_result_cb()
205 * @see stt_is_partial_result_supported()
207 typedef void (*stt_partial_result_cb)(stt_h stt, const char* data, void *user_data);
210 * @brief Called when the state of STT is changed.
212 * @param[in] stt The handle for STT
213 * @param[in] previous A previous state
214 * @param[in] current A current state
215 * @param[in] user_data The user data passed from the callback registration function.
217 * @pre An application registers this callback using stt_set_state_changed_cb() to detect changing state.
219 * @see stt_set_state_changed_cb()
220 * @see stt_unset_state_changed_cb()
222 typedef void (*stt_state_changed_cb)(stt_h stt, stt_state_e previous, stt_state_e current, void* user_data);
225 * @brief Called when error occurred.
227 * @param[in] stt The handle for STT
228 * @param[in] reason The error type (e.g. #STT_ERROR_OUT_OF_NETWORK, #STT_ERROR_IO_ERROR)
229 * @param[in] user_data The user data passed from the callback registration function
231 * @pre An application registers this callback using stt_set_error_cb() to detect error.
233 * @see stt_set_error_cb()
234 * @see stt_unset_error_cb()
236 typedef void (*stt_error_cb)(stt_h stt, stt_error_e reason, void *user_data);
239 * @brief Called to retrieve the supported languages.
241 * @param[in] stt The handle for STT
242 * @param[in] language A language is specified as an ISO 3166 alpha-2 two letter country-code \n
243 * followed by ISO 639-1 for the two-letter language code. \n
244 * For example, "ko_KR" for Korean, "en_US" for American English.
245 * @param[in] user_data The user data passed from the foreach function
247 * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop.
248 * @pre stt_foreach_supported_languages() will invoke this callback.
250 * @see stt_foreach_supported_languages()
252 typedef bool(*stt_supported_language_cb)(stt_h stt, const char* language, void* user_data);
256 * @brief Creates a handle for STT.
258 * @param[out] stt The handle for STT
260 * @return 0 on success, otherwise a negative error value
261 * @retval #STT_ERROR_NONE Successful
262 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
263 * @retval #STT_ERROR_OPERATION_FAILED Operation failure
265 * @post If this function is called, the STT state will be #STT_STATE_CREATED.
269 int stt_create(stt_h* stt);
272 * @brief Destroys the handle.
274 * @param[in] stt The handle for STT
276 * @return 0 on success, otherwise a negative error value
277 * @retval #STT_ERROR_NONE Successful
278 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
282 int stt_destroy(stt_h stt);
285 * @brief Connects the daemon.
287 * @param[in] stt The handle for STT
289 * @return 0 on success, otherwise a negative error value
290 * @retval #STT_ERROR_NONE Successful
291 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
292 * @retval #STT_ERROR_INVALID_STATE Invalid state
294 * @pre The state should be #STT_STATE_CREATED.
295 * @post If this function is called, the STT state will be #STT_STATE_READY.
297 * @see stt_unprepare()
299 int stt_prepare(stt_h stt);
302 * @brief Disconnects the daemon.
304 * @param[in] stt The handle for STT
306 * @return 0 on success, otherwise a negative error value
307 * @retval #STT_ERROR_NONE Successful
308 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
309 * @retval #STT_ERROR_INVALID_STATE Invalid state
311 * @pre The state should be #STT_STATE_READY.
312 * @post If this function is called, the STT state will be #STT_STATE_CREATED.
316 int stt_unprepare(stt_h stt);
319 * @brief Retrieves all supported languages of current engine using callback function.
321 * @param[in] stt The handle for STT
322 * @param[in] callback The callback function to invoke
323 * @param[in] user_data The user data to be passed to the callback function
325 * @return 0 on success, otherwise a negative error value
326 * @retval #STT_ERROR_NONE Successful
327 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
328 * @retval #STT_ERROR_OPERATION_FAILED Operation failure
329 * @retval #STT_ERROR_INVALID_STATE Invalid state
331 * @pre The state should be #STT_STATE_READY.
332 * @post This function invokes stt_supported_language_cb() repeatedly for getting languages.
334 * @see stt_supported_language_cb()
335 * @see stt_get_default_language()
337 int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callback, void* user_data);
340 * @brief Gets the default language set by user.
342 * @remark If the function succeeds, @a language must be released with free() by you when you no longer need it.
344 * @param[in] stt The handle for STT
345 * @param[out] language A language is specified as an ISO 3166 alpha-2 two letter country-code \n
346 * followed by ISO 639-1 for the two-letter language code. \n
347 * For example, "ko_KR" for Korean, "en_US" for American English.
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_OUT_OF_MEMORY Out of memory
353 * @retval #STT_ERROR_OPERATION_FAILED Operation failure
354 * @retval #STT_ERROR_INVALID_STATE Invalid state
356 * @pre The state should be #STT_STATE_READY.
358 * @see stt_foreach_supported_languages()
360 int stt_get_default_language(stt_h stt, char** language);
363 * @brief Gets the current state of STT.
365 * @param[in] stt The handle for STT
366 * @param[out] state The current state of STT
368 * @return 0 on success, otherwise a negative error value
369 * @retval #STT_ERROR_NONE Successful
370 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
375 * @see stt_state_changed_cb()
377 int stt_get_state(stt_h stt, stt_state_e* state);
380 * @brief Checks whether the partial results can be returned while a recognition is in process.
382 * @param[in] stt The handle for STT
383 * @param[out] partial_result The partial result status : (@c true = supported, @c false = not supported)
385 * @return 0 on success, otherwise a negative error value
386 * @retval #STT_ERROR_NONE Successful
387 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
388 * @retval #STT_ERROR_OPERATION_FAILED Operation failure
389 * @retval #STT_ERROR_INVALID_STATE Invalid state
391 * @pre The state should be #STT_STATE_READY.
393 * @see stt_partial_result_cb()
395 int stt_is_partial_result_supported(stt_h stt, bool* partial_result);
398 * @brief Sets profanity filter.
400 * @param[in] stt The handle for STT
401 * @param[in] type The option type
403 * @return 0 on success, otherwise a negative error value
404 * @retval #STT_ERROR_NONE Successful
405 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
406 * @retval #STT_ERROR_INVALID_STATE Invalid state
407 * @retval #STT_ERROR_NOT_SUPPORTED_FEATURE Not supported feature of current engine
409 * @pre The state should be #STT_STATE_READY.
411 int stt_set_profanity_filter(stt_h stt, stt_option_profanity_e type);
414 * @brief Sets punctuation override.
416 * @param[in] stt The handle for STT
417 * @param[in] type The option type
419 * @return 0 on success, otherwise a negative error value
420 * @retval #STT_ERROR_NONE Successful
421 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
422 * @retval #STT_ERROR_INVALID_STATE Invalid state
423 * @retval #STT_ERROR_NOT_SUPPORTED_FEATURE Not supported feature of current engine
425 * @pre The state should be #STT_STATE_READY.
427 int stt_set_punctuation_override(stt_h stt, stt_option_punctuation_e type);
430 * @brief Sets silence detection.
432 * @param[in] stt The handle for STT
433 * @param[in] type The option type
435 * @return 0 on success, otherwise a negative error value
436 * @retval #STT_ERROR_NONE Successful
437 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
438 * @retval #STT_ERROR_INVALID_STATE Invalid state
439 * @retval #STT_ERROR_NOT_SUPPORTED_FEATURE Not supported feature of current engine
441 * @pre The state should be #STT_STATE_READY.
443 int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type);
446 * @brief Starts recording and recognition.
448 * @remark This function starts recording in the daemon and sending recording data to engine. \n
449 * This work continues until stt_stop(), stt_cancel() or silence detected.
451 * @param[in] stt The handle for STT
452 * @param[in] language The language selected from stt_foreach_supported_languages()
453 * @param[in] type The type for recognition (e.g. #STT_RECOGNITION_TYPE_FREE, #STT_RECOGNITION_TYPE_WEB_SEARCH)
455 * @return 0 on success, otherwise a negative error value
456 * @retval #STT_ERROR_NONE Successful
457 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter.
458 * @retval #STT_ERROR_INVALID_STATE Invalid state
459 * @retval #STT_ERROR_OPERATION_FAILED Operation failure
460 * @retval #STT_ERROR_RECORDER_BUSY Recorder busy
461 * @retval #STT_ERROR_INVALID_LANGUAGE Invalid language
463 * @pre The state should be #STT_STATE_READY.
464 * @post It will invoke stt_state_changed_cb(), if you register a callback with stt_state_changed_cb(). \n
465 * If this function succeeds, the STT state will be #STT_STATE_RECORDING.
469 * @see stt_state_changed_cb()
470 * @see stt_error_cb()
472 int stt_start(stt_h stt, const char* language, const char* type);
475 * @brief Finishes recording and starts recognition processing in engine.
477 * @param[in] stt The handle for STT
479 * @return 0 on success, otherwise a negative error value
480 * @retval #STT_ERROR_NONE Successful
481 * @retval #STT_ERROR_OUT_OF_MEMORY Not enough memory
482 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
483 * @retval #STT_ERROR_INVALID_STATE Invalid state
484 * @retval #STT_ERROR_OPERATION_FAILED Operation failure
486 * @pre The state should be #STT_STATE_RECORDING.
487 * @post It will invoke stt_state_changed_cb(), if you register a callback with stt_state_changed_cb(). \n
488 * If this function succeeds, the STT state will be #STT_STATE_PROCESSING. \n
489 * After processing of engine, stt_result_cb() is called.
493 * @see stt_state_changed_cb()
494 * @see stt_error_cb()
496 int stt_stop(stt_h stt);
499 * @brief Cancels processing recognition and recording.
501 * @remark This function cancels recording and engine cancels recognition processing. \n
502 * After successful cancel, stt_state_changed_cb() is called otherwise if error is occurred, stt_error_cb() is called.
504 * @param[in] stt The handle for STT
506 * @return 0 on success, otherwise a negative error value
507 * @retval #STT_ERROR_NONE Successful
508 * @retval #STT_ERROR_OUT_OF_MEMORY Not enough memory
509 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
510 * @retval #STT_ERROR_INVALID_STATE Invalid state
511 * @retval #STT_ERROR_OPERATION_FAILED Operation failure
513 * @pre The state should be #STT_STATE_RECORDING or #STT_STATE_PROCESSING.
514 * @post It will invoke stt_state_changed_cb(), if you register a callback with stt_state_changed_cb(). \n
515 * If this function succeeds, the STT state will be #STT_STATE_READY.
519 * @see stt_state_changed_cb()
520 * @see stt_error_cb()
522 int stt_cancel(stt_h stt);
525 * @brief Gets the microphone volume during recording.
527 * @param[in] stt The handle for STT
528 * @param[out] volume Recording volume
530 * @return 0 on success, otherwise a negative error value
531 * @retval #STT_ERROR_NONE Successful
532 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
533 * @retval #STT_ERROR_INVALID_STATE Invalid state
534 * @retval #STT_ERROR_OPERATION_FAILED Operation failure
536 * @pre The state should be #STT_STATE_RECORDING.
540 int stt_get_recording_volume(stt_h stt, float* volume);
543 * @brief Registers a callback function for getting recognition result.
545 * @param[in] stt The handle for STT
546 * @param[in] callback The callback function to register
547 * @param[in] user_data The user data to be passed to the callback function
549 * @return 0 on success, otherwise a negative error value
550 * @retval #STT_ERROR_NONE Successful
551 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
552 * @retval #STT_ERROR_INVALID_STATE Invalid state
554 * @pre The state should be #STT_STATE_CREATED.
556 * @see stt_result_cb()
557 * @see stt_unset_result_cb()
559 int stt_set_result_cb(stt_h stt, stt_result_cb callback, void* user_data);
562 * @brief Unregisters the callback function.
564 * @param[in] stt The handle for STT
566 * @return 0 on success, otherwise a negative error value
567 * @retval #STT_ERROR_NONE Successful
568 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
569 * @retval #STT_ERROR_INVALID_STATE Invalid state
571 * @pre The state should be #STT_STATE_CREATED.
573 * @see stt_set_result_cb()
575 int stt_unset_result_cb(stt_h stt);
578 * @brief Registers a callback function for getting partial result of recognition.
580 * @param[in] stt The handle for STT
581 * @param[in] callback The callback function to register
582 * @param[in] user_data The user data to be passed to the callback function
584 * @return 0 on success, otherwise a negative error value
585 * @retval #STT_ERROR_NONE Successful
586 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
587 * @retval #STT_ERROR_INVALID_STATE Invalid state
589 * @pre The state should be #STT_STATE_CREATED.
591 * @see stt_partial_result_cb()
592 * @see stt_unset_partial_result_cb()
594 int stt_set_partial_result_cb(stt_h stt, stt_partial_result_cb callback, void* user_data);
597 * @brief Unregisters the callback function.
599 * @param[in] stt The handle for STT
601 * @return 0 on success, otherwise a negative error value
602 * @retval #STT_ERROR_NONE Successful
603 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
604 * @retval #STT_ERROR_INVALID_STATE Invalid state
606 * @pre The state should be #STT_STATE_CREATED.
608 * @see stt_set_partial_result_cb()
610 int stt_unset_partial_result_cb(stt_h stt);
613 * @brief Registers a callback function to be called when STT state changes.
615 * @param[in] stt The handle for STT
616 * @param[in] callback The callback function to register
617 * @param[in] user_data The user data to be passed to the callback function
619 * @return 0 on success, otherwise a negative error value
620 * @retval #STT_ERROR_NONE Successful
621 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
622 * @retval #STT_ERROR_INVALID_STATE Invalid state
624 * @pre The state should be #STT_STATE_CREATED.
626 * @see stt_state_changed_cb()
627 * @see stt_unset_state_changed_cb()
629 int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* user_data);
632 * @brief Unregisters the callback function.
634 * @param[in] stt The handle for STT
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_INVALID_STATE Invalid state
641 * @pre The state should be #STT_STATE_CREATED.
643 * @see stt_set_state_changed_cb()
645 int stt_unset_state_changed_cb(stt_h stt);
648 * @brief Registers a callback function to be called when an error occurred.
650 * @param[in] stt The handle for STT
651 * @param[in] callback The callback function to register
652 * @param[in] user_data The user data to be passed to the callback function
654 * @return 0 on success, otherwise a negative error value
655 * @retval #STT_ERROR_NONE Successful
656 * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
657 * @retval #STT_ERROR_INVALID_STATE Invalid state
659 * @pre The state should be #STT_STATE_CREATED.
661 * @see stt_error_cb()
662 * @see stt_unset_error_cb()
664 int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data);
667 * @brief Unregisters the callback function.
669 * @param[in] stt The handle for STT
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
676 * @pre The state should be #STT_STATE_CREATED.
678 * @see stt_set_error_cb()
680 int stt_unset_error_cb(stt_h stt);
691 #endif /* __STT_H__ */