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 */
53 * @brief Enumerations of callback event.
56 STTP_RESULT_EVENT_SUCCESS = 0, /**< Event when the recognition full result is ready */
57 STTP_RESULT_EVENT_NO_RESULT, /**< Event when the recognition result is not */
58 STTP_RESULT_EVENT_ERROR /**< Event when the recognition has failed */
62 * @brief Recognition type : free form dictation or default type.
64 #define STTP_RECOGNITION_TYPE_FREE "stt.recognition.type.FREE"
67 * @brief Recognition type : web search.
69 #define STTP_RECOGNITION_TYPE_WEB_SEARCH "stt.recognition.type.WEB_SEARCH"
72 * @brief Result message : None message
74 #define STTP_RESULT_MESSAGE_NONE "stt.result.message.none"
77 * @brief Result warning message : The speech has started too soon
79 #define STTP_RESULT_MESSAGE_WARNING_TOO_SOON "stt.result.message.warning.too.soon"
82 * @brief Result warning message : The speech is too short
84 #define STTP_RESULT_MESSAGE_WARNING_TOO_SHORT "stt.result.message.warning.too.short"
87 * @brief Result warning message : The speech is too long
89 #define STTP_RESULT_MESSAGE_WARNING_TOO_LONG "stt.result.message.warning.too.long"
92 * @brief Result warning message : The speech is too quiet to listen
94 #define STTP_RESULT_MESSAGE_WARNING_TOO_QUIET "stt.result.message.warning.too.quiet"
97 * @brief Result warning message : The speech is too loud to listen
99 #define STTP_RESULT_MESSAGE_WARNING_TOO_LOUD "stt.result.message.warning.too.loud"
102 * @brief Result warning message : The speech is too fast to listen
104 #define STTP_RESULT_MESSAGE_WARNING_TOO_FAST "stt.result.message.warning.too.fast"
107 * @brief Result error message : Recognition was failed because the speech started too soon
109 #define STTP_RESULT_MESSAGE_ERROR_TOO_SOON "stt.result.message.error.too.soon"
112 * @brief Result error message : Recognition was failed because the speech started too short
114 #define STTP_RESULT_MESSAGE_ERROR_TOO_SHORT "stt.result.message.error.too.short"
117 * @brief Result error message : Recognition was failed because the speech started too long
119 #define STTP_RESULT_MESSAGE_ERROR_TOO_LONG "stt.result.message.error.too.long"
122 * @brief Result error message : Recognition was failed because the speech started too quiet to listen
124 #define STTP_RESULT_MESSAGE_ERROR_TOO_QUIET "stt.result.message.error.too.quiet"
127 * @brief Result error message : Recognition was failed because the speech started too loud to listen
129 #define STTP_RESULT_MESSAGE_ERROR_TOO_LOUD "stt.result.message.error.too.loud"
132 * @brief Result error message : Recognition was failed because the speech started too fast to listen
134 #define STTP_RESULT_MESSAGE_ERROR_TOO_FAST "stt.result.message.error.too.fast"
137 * @brief Called to get recognition result.
139 * @param[in] event A result event
140 * @param[in] type A recognition type (e.g. #STTP_RECOGNITION_TYPE_FREE, #STTP_RECOGNITION_TYPE_COMMAND)
141 * @param[in] data Result texts
142 * @param[in] data_count Result text count
143 * @param[in] msg Engine message (e.g. #STTP_RESULT_MESSAGE_WARNING_TOO_SOON, #STTP_RESULT_MESSAGE_ERROR_TOO_SHORT)
144 * @param[in] user_data The user data passed from the start function
146 * @pre sttpe_stop() will invoke this callback.
151 typedef void (*sttpe_result_cb)(sttp_result_event_e event, const char* type,
152 const char** data, int data_count, const char* msg, void *user_data);
155 * @brief Called to get partial recognition result.
157 * @param[in] event A result event
158 * @param[in] data A result text
159 * @param[in] user_data The user data passed from the start function.
161 * @pre sttpe_set_recording_data() will invoke this callback
163 * @see sttpe_set_recording_data()
165 typedef void (*sttpe_partial_result_cb)(sttp_result_event_e event, const char* data, void *user_data);
168 * @brief Called to detect silence from recording data.
170 * @param[in] user_data The user data passed from the start function.
172 * @pre sttpe_set_recording_data() will invoke this callback.
174 * @see sttpe_set_recording_data()
176 typedef void (*sttpe_silence_detected_cb)(void *user_data);
179 * @brief Called to retrieve the supported languages.
181 * @param[in] language A language is specified as an ISO 3166 alpha-2 two letter country-code
182 * followed by ISO 639-1 for the two-letter language code \n
183 * For example, "ko_KR" for Korean, "en_US" for American English
184 * @param[in] user_data The user data passed from the foreach function
186 * @return @c true to continue with the next iteration of the loop \n @c false to break out of the loop
188 * @pre sttpe_foreach_supported_languages() will invoke this callback.
190 * @see sttpe_foreach_supported_languages()
192 typedef bool (*sttpe_supported_language_cb)(const char* language, void* user_data);
195 * @brief Called to retrieve the supported engine settings.
197 * @param[in] key A key
198 * @param[in] value A value
199 * @param[in] user_data The user data passed from the foreach function
201 * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop.
202 * @pre sttpe_foreach_engine_settings() will invoke this callback.
204 * @see sttpe_foreach_engine_settings()
206 typedef bool (*sttpe_engine_setting_cb)(const char* key, const char* value, void* user_data);
209 * @brief Initializes the engine.
211 * @param[in] result_cb A callback function for recognition result
212 * @param[in] partial_result_cb A callback function for partial recognition result
213 * @param[in] silence_cb A callback function for silence detection
215 * @return 0 on success, otherwise a negative error value
216 * @retval #STTP_ERROR_NONE Successful
217 * @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
218 * @retval #STTP_ERROR_INVALID_STATE Already initialized
219 * @retval #STTP_ERROR_OPERATION_FAILED Operation failed
221 * @see sttpe_deinitialize()
223 typedef int (* sttpe_initialize)(sttpe_result_cb result_cb, sttpe_partial_result_cb partial_result_cb,
224 sttpe_silence_detected_cb silence_cb);
227 * @brief Deinitializes the engine
229 * @return 0 on success, otherwise a negative error value
230 * @retval #STTP_ERROR_NONE Successful
231 * @retval #STTP_ERROR_INVALID_STATE Not initialized
233 * @see sttpe_initialize()
235 typedef int (* sttpe_deinitialize)(void);
238 * @brief Retrieves all supported languages of the engine.
240 * @param[in] callback a callback function
241 * @param[in] user_data The user data to be passed to the callback function
243 * @return 0 on success, otherwise a negative error value
244 * @retval #STTP_ERROR_NONE Successful
245 * @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
246 * @retval #STTP_ERROR_INVALID_STATE Not initialized
248 * @post This function invokes sttpe_supported_language_cb() repeatedly for getting supported languages.
250 * @see sttpe_supported_language_cb()
252 typedef int (* sttpe_foreach_supported_languages)(sttpe_supported_language_cb callback, void* user_data);
255 * @brief Checks whether a language is valid or not.
257 * @param[in] language A language
259 * @return 0 on success, otherwise a negative error value
260 * @retval #STTP_ERROR_NONE Successful
261 * @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
262 * @retval #STTP_ERROR_INVALID_STATE Not initialized
264 * @see sttpe_foreach_supported_languages()
266 typedef bool (* sttpe_is_valid_language)(const char* language);
269 * @brief Gets whether the engine supports silence detection.
271 * @return 0 on success, otherwise a negative error value
272 * @retval #STTP_ERROR_NONE Successful
273 * @retval #STTP_ERROR_INVALID_STATE Not initialized
275 typedef bool (* sttpe_support_silence_detection)(void);
278 * @brief Gets supporting partial result.
280 * @return 0 on success, otherwise a negative error value
281 * @retval #STTP_ERROR_NONE Successful
282 * @retval #STTP_ERROR_INVALID_STATE Not initialized
284 typedef bool (* sttpe_support_partial_result)(void);
287 * @brief Gets recording format of the engine.
289 * @param[out] types The format used by the recorder.
290 * @param[out] rate The sample rate used by the recorder.
291 * @param[out] channels The number of channels used by the recorder.
293 * @return 0 on success, otherwise a negative error value
294 * @retval #STTP_ERROR_NONE Successful
295 * @retval #STTP_ERROR_INVALID_STATE Not initialized
297 typedef int (* sttpe_get_recording_format)(sttp_audio_type_e* types, int* rate, int* channels);
300 * @brief Sets profanity filter option.
302 * @param[in] value A value
304 * @return 0 on success, otherwise a negative error value
305 * @retval #STTP_ERROR_NONE Successful
306 * @retval #STTP_ERROR_INVALID_STATE Not initialized
307 * @retval #STTP_ERROR_NOT_SUPPORTED_FEATURE Not supported feature
309 typedef int (* sttpe_set_profanity_filter)(bool value);
312 * @brief Sets punctuation option.
314 * @param[in] value A value
316 * @return 0 on success, otherwise a negative error value
317 * @retval #STTP_ERROR_NONE Successful
318 * @retval #STTP_ERROR_INVALID_STATE Not initialized
319 * @retval #STTP_ERROR_NOT_SUPPORTED_FEATURE Not supported feature
321 typedef int (* sttpe_set_punctuation_override)(bool value);
324 * @brief Sets silence detection option.
326 * @param[in] value A value
328 * @return 0 on success, otherwise a negative error value
329 * @retval #STTP_ERROR_NONE Successful
330 * @retval #STTP_ERROR_INVALID_STATE Not initialized
331 * @retval #STTP_ERROR_NOT_SUPPORTED_FEATURE Not supported feature
333 typedef int (* sttpe_set_silence_detection)(bool value);
336 * @brief Start recognition.
338 * @param[in] language A language.
339 * @param[in] type A recognition type. (e.g. #STTP_RECOGNITION_TYPE_FREE, #STTP_RECOGNITION_TYPE_WEB_SEARCH)
340 * @param[in] user_data The user data to be passed to the callback function.
342 * @return 0 on success, otherwise a negative error value
343 * @retval #STTP_ERROR_NONE Successful
344 * @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
345 * @retval #STTP_ERROR_INVALID_STATE Invalid state
346 * @retval #STTP_ERROR_INVALID_LANGUAGE Invalid language
347 * @retval #STTP_ERROR_OPERATION_FAILED Operation failed
348 * @retval #STTP_ERROR_OUT_OF_NETWORK Out of network
350 * @pre The engine is not in recognition processing.
352 * @see sttpe_set_recording_data()
354 * @see sttpe_cancel()
356 typedef int (* sttpe_start)(const char* language, const char* type, void *user_data);
359 * @brief Sets recording data for speech recognition from recorder.
361 * @remark This function should be returned immediately after recording data copy.
363 * @param[in] data A recording data
364 * @param[in] length A length of recording data
366 * @return 0 on success, otherwise a negative error value
367 * @retval #STTP_ERROR_NONE Successful
368 * @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
369 * @retval #STTP_ERROR_INVALID_STATE Invalid state
371 * @pre sttpe_start() should succeed.
372 * @post If the engine supports partial result, it will invoke sttpe_partial_result_cb().
375 * @see sttpe_cancel()
377 * @see sttpe_partial_result_cb()
379 typedef int (* sttpe_set_recording_data)(const void* data, unsigned int length);
382 * @brief Stops to set recording data.
384 * @return 0 on success, otherwise a negative error value
385 * @retval #STTP_ERROR_NONE Successful
386 * @retval #STTP_ERROR_INVALID_STATE Invalid state
387 * @retval #STTP_ERROR_OPERATION_FAILED Operation failed
388 * @retval #STTP_ERROR_OUT_OF_NETWORK Out of network
390 * @pre sttpe_start() should succeed.
391 * @post After processing of the engine, sttpe_result_cb() is called.
394 * @see sttpe_set_recording_data()
395 * @see sttpe_result_cb()
396 * @see sttpe_cancel()
398 typedef int (* sttpe_stop)(void);
401 * @brief Cancels the recognition process.
403 * @return 0 on success, otherwise a negative error value.
404 * @retval #STTP_ERROR_NONE Successful.
405 * @retval #STTP_ERROR_INVALID_STATE Invalid state.
406 * @pre STT engine is in recognition processing.
411 typedef int (* sttpe_cancel)(void);
414 * @brief Convert file to text.
416 * @param[in] filepath Sound file.
417 * @param[in] language A language.
418 * @param[in] type A recognition type. (e.g. #STTP_RECOGNITION_TYPE_FREE, #STTP_RECOGNITION_TYPE_WEB_SEARCH)
419 * @param[in] user_data The user data to be passed to the callback function.
421 * @return 0 on success, otherwise a negative error value
422 * @retval #STTP_ERROR_NONE Successful
423 * @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
424 * @retval #STTP_ERROR_INVALID_STATE Invalid state
425 * @retval #STTP_ERROR_INVALID_LANGUAGE Invalid language
426 * @retval #STTP_ERROR_OPERATION_FAILED Operation failed
427 * @retval #STTP_ERROR_OUT_OF_NETWORK Out of network
429 * @pre The engine is not in recognition processing.
431 * @see sttpe_result_cb()
433 typedef int (* sttpe_start_file_recognition)(const char* filepath, const char* language, const char* type, void *user_data);
436 * @brief Gets setting information of the engine.
438 * @param[in] callback A callback function.
439 * @param[in] user_data The user data to be passed to the callback function.
441 * @return 0 on success, otherwise a negative error value
442 * @retval #STTP_ERROR_NONE Successful
443 * @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
444 * @retval #STTP_ERROR_INVALID_STATE Not initialized
445 * @retval #STTP_ERROR_OPERATION_FAILED Operation failed
447 * @post This function invokes sttpe_engine_setting_cb() repeatedly for getting engine settings.
449 * @see sttpe_engine_setting_cb()
451 typedef int (* sttpe_foreach_engine_settings)(sttpe_engine_setting_cb callback, void* user_data);
454 * @brief Set engine specific information.
456 * @param[in] key A key
457 * @param[in] value A value
459 * @return 0 on success, otherwise a negative error value
460 * @retval #STTP_ERROR_NONE Successful
461 * @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
462 * @retval #STTP_ERROR_INVALID_STATE Not initialized
463 * @retval #STTP_ERROR_OPERATION_FAILED Operation failed
465 * @see sttpe_foreach_engine_settings()
467 typedef int (* sttpe_set_engine_setting)(const char* key, const char* value);
471 * @brief A structure of the engine functions.
474 int size; /**< Size of structure */
475 int version; /**< Version */
477 sttpe_initialize initialize; /**< Initialize engine */
478 sttpe_deinitialize deinitialize; /**< Shutdown engine */
480 /* Get engine information */
481 sttpe_foreach_supported_languages foreach_langs; /**< Foreach language list */
482 sttpe_is_valid_language is_valid_lang; /**< Check language */
483 sttpe_support_silence_detection support_silence; /**< Get silence detection support */
484 sttpe_support_partial_result support_partial_result; /**< Get partial result support */
485 sttpe_get_recording_format get_audio_format; /**< Get audio format */
487 /* Set engine information */
488 sttpe_set_profanity_filter set_profanity_filter; /**< Set profanity filter */
489 sttpe_set_punctuation_override set_punctuation; /**< Set punctuation override */
490 sttpe_set_silence_detection set_silence_detection; /**< Set silence detection */
492 /* Control recognition */
493 sttpe_start start; /**< Start recognition */
494 sttpe_set_recording_data set_recording; /**< Set recording data */
495 sttpe_stop stop; /**< Shutdown function */
496 sttpe_cancel cancel; /**< Cancel recognition or cancel thinking */
497 sttpe_start_file_recognition start_file_recognition; /**< Start file recognition */
500 sttpe_foreach_engine_settings foreach_engine_settings;/**< Foreach engine specific info */
501 sttpe_set_engine_setting set_engine_setting; /**< Set engine specific info */
505 * @brief A structure of the daemon functions.
508 int size; /**< size */
509 int version; /**< version */
514 * @brief Loads the engine.
516 * @param[in] pdfuncs The daemon functions
517 * @param[out] pefuncs The engine functions
519 * @return This function returns zero on success, or negative with error code on failure
520 * @retval #STTP_ERROR_NONE Successful
521 * @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
522 * @retval #STTP_ERROR_OPERATION_FAILED Operation failed
524 * @pre The sttp_get_engine_info() should be successful.
525 * @post The daemon calls engine functions of sttpe_funcs_s.
527 * @see sttp_get_engine_info()
528 * @see sttp_unload_engine()
530 int sttp_load_engine(sttpd_funcs_s* pdfuncs, sttpe_funcs_s* pefuncs);
533 * @brief Unloads this engine by the daemon.
535 * @pre The sttp_load_engine() should be successful.
537 * @see sttp_load_engine()
539 void sttp_unload_engine(void);
542 * @brief Called to get the engine base information.
544 * @param[in] engine_uuid The engine id
545 * @param[in] engine_name The engine name
546 * @param[in] setting_ug_name The setting ug name
547 * @param[in] use_network @c true to need network @c false not to need network.
548 * @param[in] user_data The User data passed from sttp_get_engine_info()
550 * @pre sttp_get_engine_info() will invoke this callback.
552 * @see sttp_get_engine_info()
554 typedef void (*sttpe_engine_info_cb)(const char* engine_uuid, const char* engine_name, const char* setting_ug_name,
555 bool use_network, void* user_data);
558 * @brief Gets the engine base information before the engine is loaded by the daemon.
560 * @param[in] callback Callback function
561 * @param[in] user_data User data to be passed to the callback function
563 * @return This function returns zero on success, or negative with error code on failure
564 * @retval #STTP_ERROR_NONE Successful
565 * @retval #STTP_ERROR_INVALID_PARAMETER Invalid parameter
566 * @retval #STTP_ERROR_OPERATION_FAILED Operation failed
568 * @post This function invokes sttpe_engine_info_cb() for getting engine information.
570 * @see sttpe_engine_info_cb()
571 * @see sttp_load_engine()
573 int sttp_get_engine_info(sttpe_engine_info_cb callback, void* user_data);
583 #endif /* __STTP_H__ */