2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
21 * @addtogroup STT_ENGINE_MODULE
30 * @brief Enumerations of error codes.
33 STTP_ERROR_NONE = 0, /**< Successful */
34 STTP_ERROR_OUT_OF_MEMORY = -ENOMEM, /**< Out of Memory */
35 STTP_ERROR_IO_ERROR = -EIO, /**< I/O error */
36 STTP_ERROR_INVALID_PARAMETER = -EINVAL, /**< Invalid parameter */
37 STTP_ERROR_OUT_OF_NETWORK = -ENETDOWN, /**< Out of network */
38 STTP_ERROR_INVALID_STATE = -0x0100031, /**< Invalid state */
39 STTP_ERROR_INVALID_LANGUAGE = -0x0100032, /**< Invalid language */
40 STTP_ERROR_OPERATION_FAILED = -0x0100034, /**< Operation failed */
41 STTP_ERROR_NOT_SUPPORTED_FEATURE= -0x0100035 /**< Not supported feature */
45 * @brief Enumerations of audio type.
48 STTP_AUDIO_TYPE_PCM_S16_LE = 0, /**< Signed 16bit audio type, Little endian */
49 STTP_AUDIO_TYPE_PCM_U8, /**< Unsigned 8bit audio type */
50 STTP_AUDIO_TYPE_AMR /**< AMR audio type */
54 * @brief Enumerations of callback event.
57 STTP_RESULT_EVENT_SUCCESS = 0, /**< Event when the recognition full result is ready */
58 STTP_RESULT_EVENT_NO_RESULT, /**< Event when the recognition result is not */
59 STTP_RESULT_EVENT_ERROR /**< Event when the recognition has failed */
63 * @brief Recognition type : free form dictation or default type.
65 #define STTP_RECOGNITION_TYPE_FREE "stt.recognition.type.FREE"
68 * @brief Recognition type : web search.
70 #define STTP_RECOGNITION_TYPE_WEB_SEARCH "stt.recognition.type.WEB_SEARCH"
73 * @brief Recognition type : all voice commands.
75 #define STTP_RECOGNITION_TYPE_COMMAND "stt.recognition.type.COMMAND"
78 * @brief Recognition type : call of voice commands.
80 #define STTP_RECOGNITION_TYPE_COMMAND_CALL "stt.recognition.type.COMMAND.CALL"
83 * @brief Recognition type : music of voice commands.
85 #define STTP_RECOGNITION_TYPE_COMMAND_MUSIC "stt.recognition.type.COMMAND.MUSIC"
88 * @brief Recognition type : web search of voice commands.
90 #define STTP_RECOGNITION_TYPE_COMMAND_WEB_SEARCH "stt.recognition.type.COMMAND.WEB_SEARCH"
93 * @brief Recognition type : schedule of voice commands.
95 #define STTP_RECOGNITION_TYPE_COMMAND_SCHEDULE "stt.recognition.type.COMMAND.SCHEDULE"
98 * @brief Recognition type : search of voice commands.
100 #define STTP_RECOGNITION_TYPE_COMMAND_SEARCH "stt.recognition.type.COMMAND.SEARCH"
103 * @brief Recognition type : contact of voice commands.
105 #define STTP_RECOGNITION_TYPE_COMMAND_CONTACT "stt.recognition.type.COMMAND.CONTACT"
108 * @brief Recognition type : social of voice commands.
110 #define STTP_RECOGNITION_TYPE_COMMAND_SOCIAL "stt.recognition.type.COMMAND.SOCIAL"
113 * @brief Recognition type : message of voice commands.
115 #define STTP_RECOGNITION_TYPE_COMMAND_MESSAGE "stt.recognition.type.COMMAND.MESSAGE"
118 * @brief Recognition type : email of voice commands.
120 #define STTP_RECOGNITION_TYPE_COMMAND_EMAIL "stt.recognition.type.COMMAND.EMAIL"
123 * @brief Recognition type : memo of voice commands.
125 #define STTP_RECOGNITION_TYPE_COMMAND_MEMO "stt.recognition.type.COMMAND.MEMO"
128 * @brief Recognition type : alarm of voice commands.
130 #define STTP_RECOGNITION_TYPE_COMMAND_ALARM "stt.recognition.type.COMMAND.ALARM"
133 * @brief Recognition type : application of voice commands.
135 #define STTP_RECOGNITION_TYPE_COMMAND_APPLICATION "stt.recognition.type.COMMAND.APPLICATION"
138 * @brief Recognition type : driving mode of voice commands.
140 #define STTP_RECOGNITION_TYPE_COMMAND_DRIVING_MODE "stt.recognition.type.COMMAND.DRIVING_MODE"
143 * @brief Recognition type : navigation of voice commands.
145 #define STTP_RECOGNITION_TYPE_COMMAND_NAVIGATION "stt.recognition.type.COMMAND.NAVIGATION"
148 * @brief Recognition type : text-to-speech of voice commands.
150 #define STTP_RECOGNITION_TYPE_COMMAND_TTS "stt.recognition.type.COMMAND.TTS"
153 * @brief Result message : None message
155 #define STTP_RESULT_MESSAGE_NONE "stt.result.message.none"
158 * @brief Result warning message : The speech has started too soon
160 #define STTP_RESULT_MESSAGE_WARNING_TOO_SOON "stt.result.message.warning.too.soon"
163 * @brief Result warning message : The speech is too short
165 #define STTP_RESULT_MESSAGE_WARNING_TOO_SHORT "stt.result.message.warning.too.short"
168 * @brief Result warning message : The speech is too long
170 #define STTP_RESULT_MESSAGE_WARNING_TOO_LONG "stt.result.message.warning.too.long"
173 * @brief Result warning message : The speech is too quiet to listen
175 #define STTP_RESULT_MESSAGE_WARNING_TOO_QUIET "stt.result.message.warning.too.quiet"
178 * @brief Result warning message : The speech is too loud to listen
180 #define STTP_RESULT_MESSAGE_WARNING_TOO_LOUD "stt.result.message.warning.too.loud"
183 * @brief Result warning message : The speech is too fast to listen
185 #define STTP_RESULT_MESSAGE_WARNING_TOO_FAST "stt.result.message.warning.too.fast"
188 * @brief Result error message : Recognition was failed because the speech started too soon
190 #define STTP_RESULT_MESSAGE_ERROR_TOO_SOON "stt.result.message.error.too.soon"
193 * @brief Result error message : Recognition was failed because the speech started too short
195 #define STTP_RESULT_MESSAGE_ERROR_TOO_SHORT "stt.result.message.error.too.short"
198 * @brief Result error message : Recognition was failed because the speech started too long
200 #define STTP_RESULT_MESSAGE_ERROR_TOO_LONG "stt.result.message.error.too.long"
203 * @brief Result error message : Recognition was failed because the speech started too quiet to listen
205 #define STTP_RESULT_MESSAGE_ERROR_TOO_QUIET "stt.result.message.error.too.quiet"
208 * @brief Result error message : Recognition was failed because the speech started too loud to listen
210 #define STTP_RESULT_MESSAGE_ERROR_TOO_LOUD "stt.result.message.error.too.loud"
213 * @brief Result error message : Recognition was failed because the speech started too fast to listen
215 #define STTP_RESULT_MESSAGE_ERROR_TOO_FAST "stt.result.message.error.too.fast"
218 * @brief Called to get recognition result.
220 * @param[in] event A result event
221 * @param[in] type A recognition type (e.g. #STTP_RECOGNITION_TYPE_FREE, #STTP_RECOGNITION_TYPE_COMMAND)
222 * @param[in] data Result texts
223 * @param[in] data_count Result text count
224 * @param[in] msg Engine message (e.g. #STTP_RESULT_MESSAGE_WARNING_TOO_SOON, #STTP_RESULT_MESSAGE_ERROR_TOO_SHORT)
225 * @param[in] user_data The user data passed from the start function
227 * @pre sttpe_stop() will invoke this callback.
232 typedef void (*sttpe_result_cb)(sttp_result_event_e event, const char* type,
233 const char** data, int data_count, const char* msg, void *user_data);
236 * @brief Called to get partial recognition result.
238 * @param[in] event A result event
239 * @param[in] data A result text
240 * @param[in] user_data The user data passed from the start function.
242 * @pre sttpe_set_recording_data() will invoke this callback
244 * @see sttpe_set_recording_data()
246 typedef void (*sttpe_partial_result_cb)(sttp_result_event_e event, const char* data, void *user_data);
249 * @brief Called to detect silence from recording data.
251 * @param[in] user_data The user data passed from the start function.
253 * @pre sttpe_set_recording_data() will invoke this callback.
255 * @see sttpe_set_recording_data()
257 typedef void (*sttpe_silence_detected_cb)(void *user_data);
260 * @brief Called to retrieve the supported languages.
262 * @param[in] language A language is specified as an ISO 3166 alpha-2 two letter country-code
263 * followed by ISO 639-1 for the two-letter language code \n
264 * For example, "ko_KR" for Korean, "en_US" for American English
265 * @param[in] user_data The user data passed from the foreach function
267 * @return @c true to continue with the next iteration of the loop \n @c false to break out of the loop
269 * @pre sttpe_foreach_supported_languages() will invoke this callback.
271 * @see sttpe_foreach_supported_languages()
273 typedef bool (*sttpe_supported_language_cb)(const char* language, void* user_data);
276 * @brief Called to retrieve the supported engine settings.
278 * @param[in] key A key
279 * @param[in] value A value
280 * @param[in] user_data The user data passed from the foreach function
282 * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop.
283 * @pre sttpe_foreach_engine_settings() will invoke this callback.
285 * @see sttpe_foreach_engine_settings()
287 typedef bool (*sttpe_engine_setting_cb)(const char* key, const char* value, void* user_data);
290 * @brief Initializes the engine.
292 * @param[in] result_cb A callback function for recognition result
293 * @param[in] partial_result_cb A callback function for partial recognition result
294 * @param[in] silence_cb A callback function for silence detection
296 * @return 0 on success, otherwise a negative error value
297 * @retval #STTP_ERROR_NONE Successful
298 * @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
299 * @retval #STTP_ERROR_INVALID_STATE Already initialized
300 * @retval #STTP_ERROR_OPERATION_FAILED Operation failed
302 * @see sttpe_deinitialize()
304 typedef int (* sttpe_initialize)(sttpe_result_cb result_cb, sttpe_partial_result_cb partial_result_cb,
305 sttpe_silence_detected_cb silence_cb);
308 * @brief Deinitializes the engine
310 * @return 0 on success, otherwise a negative error value
311 * @retval #STTP_ERROR_NONE Successful
312 * @retval #STTP_ERROR_INVALID_STATE Not initialized
314 * @see sttpe_initialize()
316 typedef int (* sttpe_deinitialize)(void);
319 * @brief Retrieves all supported languages of the engine.
321 * @param[in] callback a callback function
322 * @param[in] user_data The user data to be passed to the callback function
324 * @return 0 on success, otherwise a negative error value
325 * @retval #STTP_ERROR_NONE Successful
326 * @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
327 * @retval #STTP_ERROR_INVALID_STATE Not initialized
329 * @post This function invokes sttpe_supported_language_cb() repeatedly for getting supported languages.
331 * @see sttpe_supported_language_cb()
333 typedef int (* sttpe_foreach_supported_languages)(sttpe_supported_language_cb callback, void* user_data);
336 * @brief Checks whether a language is valid or not.
338 * @param[in] language A language
340 * @return 0 on success, otherwise a negative error value
341 * @retval #STTP_ERROR_NONE Successful
342 * @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
343 * @retval #STTP_ERROR_INVALID_STATE Not initialized
345 * @see sttpe_foreach_supported_languages()
347 typedef bool (* sttpe_is_valid_language)(const char* language);
350 * @brief Gets whether the engine supports silence detection.
352 * @return 0 on success, otherwise a negative error value
353 * @retval #STTP_ERROR_NONE Successful
354 * @retval #STTP_ERROR_INVALID_STATE Not initialized
356 typedef bool (* sttpe_support_silence_detection)(void);
359 * @brief Gets supporting partial result.
361 * @return 0 on success, otherwise a negative error value
362 * @retval #STTP_ERROR_NONE Successful
363 * @retval #STTP_ERROR_INVALID_STATE Not initialized
365 typedef bool (* sttpe_support_partial_result)(void);
368 * @brief Gets recording format of the engine.
370 * @param[out] types The format used by the recorder.
371 * @param[out] rate The sample rate used by the recorder.
372 * @param[out] channels The number of channels used by the recorder.
374 * @return 0 on success, otherwise a negative error value
375 * @retval #STTP_ERROR_NONE Successful
376 * @retval #STTP_ERROR_INVALID_STATE Not initialized
378 typedef int (* sttpe_get_recording_format)(sttp_audio_type_e* types, int* rate, int* channels);
381 * @brief Sets profanity filter option.
383 * @param[in] value A value
385 * @return 0 on success, otherwise a negative error value
386 * @retval #STTP_ERROR_NONE Successful
387 * @retval #STTP_ERROR_INVALID_STATE Not initialized
388 * @retval #STTP_ERROR_NOT_SUPPORTED_FEATURE Not supported feature
390 typedef int (* sttpe_set_profanity_filter)(bool value);
393 * @brief Sets punctuation option.
395 * @param[in] value A value
397 * @return 0 on success, otherwise a negative error value
398 * @retval #STTP_ERROR_NONE Successful
399 * @retval #STTP_ERROR_INVALID_STATE Not initialized
400 * @retval #STTP_ERROR_NOT_SUPPORTED_FEATURE Not supported feature
402 typedef int (* sttpe_set_punctuation_override)(bool value);
405 * @brief Sets silence detection option.
407 * @param[in] value A value
409 * @return 0 on success, otherwise a negative error value
410 * @retval #STTP_ERROR_NONE Successful
411 * @retval #STTP_ERROR_INVALID_STATE Not initialized
412 * @retval #STTP_ERROR_NOT_SUPPORTED_FEATURE Not supported feature
414 typedef int (* sttpe_set_silence_detection)(bool value);
417 * @brief Start recognition.
419 * @param[in] language A language.
420 * @param[in] type A recognition type. (e.g. #STTP_RECOGNITION_TYPE_FREE, #STTP_RECOGNITION_TYPE_WEB_SEARCH)
421 * @param[in] user_data The user data to be passed to the callback function.
423 * @return 0 on success, otherwise a negative error value
424 * @retval #STTP_ERROR_NONE Successful
425 * @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
426 * @retval #STTP_ERROR_INVALID_STATE Invalid state
427 * @retval #STTP_ERROR_INVALID_LANGUAGE Invalid language
428 * @retval #STTP_ERROR_OPERATION_FAILED Operation failed
429 * @retval #STTP_ERROR_OUT_OF_NETWORK Out of network
431 * @pre The engine is not in recognition processing.
433 * @see sttpe_set_recording_data()
435 * @see sttpe_cancel()
437 typedef int (* sttpe_start)(const char* language, const char* type, void *user_data);
440 * @brief Sets recording data for speech recognition from recorder.
442 * @remark This function should be returned immediately after recording data copy.
444 * @param[in] data A recording data
445 * @param[in] length A length of recording data
447 * @return 0 on success, otherwise a negative error value
448 * @retval #STTP_ERROR_NONE Successful
449 * @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
450 * @retval #STTP_ERROR_INVALID_STATE Invalid state
452 * @pre sttpe_start() should succeed.
453 * @post If the engine supports partial result, it will invoke sttpe_partial_result_cb().
456 * @see sttpe_cancel()
458 * @see sttpe_partial_result_cb()
460 typedef int (* sttpe_set_recording_data)(const void* data, unsigned int length);
463 * @brief Stops to set recording data.
465 * @return 0 on success, otherwise a negative error value
466 * @retval #STTP_ERROR_NONE Successful
467 * @retval #STTP_ERROR_INVALID_STATE Invalid state
468 * @retval #STTP_ERROR_OPERATION_FAILED Operation failed
469 * @retval #STTP_ERROR_OUT_OF_NETWORK Out of network
471 * @pre sttpe_start() should succeed.
472 * @post After processing of the engine, sttpe_result_cb() is called.
475 * @see sttpe_set_recording_data()
476 * @see sttpe_result_cb()
477 * @see sttpe_cancel()
479 typedef int (* sttpe_stop)(void);
482 * @brief Cancels the recognition process.
484 * @return 0 on success, otherwise a negative error value.
485 * @retval #STTP_ERROR_NONE Successful.
486 * @retval #STTP_ERROR_INVALID_STATE Invalid state.
487 * @pre STT engine is in recognition processing.
492 typedef int (* sttpe_cancel)(void);
495 * @brief Gets setting information of the engine.
497 * @param[in] callback A callback function.
498 * @param[in] user_data The user data to be passed to the callback function.
500 * @return 0 on success, otherwise a negative error value
501 * @retval #STTP_ERROR_NONE Successful
502 * @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
503 * @retval #STTP_ERROR_INVALID_STATE Not initialized
504 * @retval #STTP_ERROR_OPERATION_FAILED Operation failed
506 * @post This function invokes sttpe_engine_setting_cb() repeatedly for getting engine settings.
508 * @see sttpe_engine_setting_cb()
510 typedef int (* sttpe_foreach_engine_settings)(sttpe_engine_setting_cb callback, void* user_data);
513 * @brief Set engine specific information.
515 * @param[in] key A key
516 * @param[in] value A value
518 * @return 0 on success, otherwise a negative error value
519 * @retval #STTP_ERROR_NONE Successful
520 * @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
521 * @retval #STTP_ERROR_INVALID_STATE Not initialized
522 * @retval #STTP_ERROR_OPERATION_FAILED Operation failed
524 * @see sttpe_foreach_engine_settings()
526 typedef int (* sttpe_set_engine_setting)(const char* key, const char* value);
530 * @brief A structure of the engine functions.
533 int size; /**< Size of structure */
534 int version; /**< Version */
536 sttpe_initialize initialize; /**< Initialize engine */
537 sttpe_deinitialize deinitialize; /**< Shutdown engine */
539 /* Get engine information */
540 sttpe_foreach_supported_languages foreach_langs; /**< Foreach language list */
541 sttpe_is_valid_language is_valid_lang; /**< Check language */
542 sttpe_support_silence_detection support_silence; /**< Get silence detection support */
543 sttpe_support_partial_result support_partial_result; /**< Get partial result support */
544 sttpe_get_recording_format get_audio_format; /**< Get audio format */
546 /* Set engine information */
547 sttpe_set_profanity_filter set_profanity_filter; /**< Set profanity filter */
548 sttpe_set_punctuation_override set_punctuation; /**< Set punctuation override */
549 sttpe_set_silence_detection set_silence_detection; /**< Set silence detection */
551 /* Control recognition */
552 sttpe_start start; /**< Start recognition */
553 sttpe_set_recording_data set_recording; /**< Set recording data */
554 sttpe_stop stop; /**< Shutdown function */
555 sttpe_cancel cancel; /**< Cancel recognition or cancel thinking */
558 sttpe_foreach_engine_settings foreach_engine_settings;/**< Foreach engine specific info */
559 sttpe_set_engine_setting set_engine_setting; /**< Set engine specific info */
563 * @brief A structure of the daemon functions.
566 int size; /**< size */
567 int version; /**< version */
572 * @brief Loads the engine.
574 * @param[in] pdfuncs The daemon functions
575 * @param[out] pefuncs The engine functions
577 * @return This function returns zero on success, or negative with error code on failure
578 * @retval #STTP_ERROR_NONE Successful
579 * @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
580 * @retval #STTP_ERROR_OPERATION_FAILED Operation failed
582 * @pre The sttp_get_engine_info() should be successful.
583 * @post The daemon calls engine functions of sttpe_funcs_s.
585 * @see sttp_get_engine_info()
586 * @see sttp_unload_engine()
588 int sttp_load_engine(sttpd_funcs_s* pdfuncs, sttpe_funcs_s* pefuncs);
591 * @brief Unloads this engine by the daemon.
593 * @pre The sttp_load_engine() should be successful.
595 * @see sttp_load_engine()
597 void sttp_unload_engine(void);
600 * @brief Called to get the engine base information.
602 * @param[in] engine_uuid The engine id
603 * @param[in] engine_name The engine name
604 * @param[in] setting_ug_name The setting ug name
605 * @param[in] use_network @c true to need network @c false not to need network.
606 * @param[in] user_data The User data passed from sttp_get_engine_info()
608 * @pre sttp_get_engine_info() will invoke this callback.
610 * @see sttp_get_engine_info()
612 typedef void (*sttpe_engine_info_cb)(const char* engine_uuid, const char* engine_name, const char* setting_ug_name,
613 bool use_network, void* user_data);
616 * @brief Gets the engine base information before the engine is loaded by the daemon.
618 * @param[in] callback Callback function
619 * @param[in] user_data User data to be passed to the callback function
621 * @return This function returns zero on success, or negative with error code on failure
622 * @retval #STTP_ERROR_NONE Successful
623 * @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
624 * @retval #STTP_ERROR_OPERATION_FAILED Operation failed
626 * @post This function invokes sttpe_engine_info_cb() for getting engine information.
628 * @see sttpe_engine_info_cb()
629 * @see sttp_load_engine()
631 int sttp_get_engine_info(sttpe_engine_info_cb callback, void* user_data);
641 #endif /* __STTP_H__ */