2 * Copyright (c) 2011-2016 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 #include "stt_engine.h"
24 * Internal data structure
32 sttpe_funcs_s* pefuncs;
33 sttpd_funcs_s* pdfuncs;
35 int (*sttp_load_engine)(sttpd_funcs_s* pdfuncs, sttpe_funcs_s* pefuncs);
36 int (*sttp_unload_engine)();
39 extern const char* stt_tag();
41 /** stt engine list */
42 static GSList *g_engine_list;
44 static const char* __stt_get_engine_error_code(sttp_error_e err)
47 case STTP_ERROR_NONE: return "STTP_ERROR_NONE";
48 case STTP_ERROR_OUT_OF_MEMORY: return "STTP_ERROR_OUT_OF_MEMORY";
49 case STTP_ERROR_IO_ERROR: return "STTP_ERROR_IO_ERROR";
50 case STTP_ERROR_INVALID_PARAMETER: return "STTP_ERROR_INVALID_PARAMETER";
51 case STTP_ERROR_TIMED_OUT: return "STTP_ERROR_TIMED_OUT";
52 case STTP_ERROR_RECORDER_BUSY: return "STTP_ERROR_RECORDER_BUSY";
53 case STTP_ERROR_OUT_OF_NETWORK: return "STTP_ERROR_OUT_OF_NETWORK";
54 case STTP_ERROR_PERMISSION_DENIED: return "STTP_ERROR_PERMISSION_DENIED";
55 case STTP_ERROR_NOT_SUPPORTED: return "STTP_ERROR_NOT_SUPPORTED";
56 case STTP_ERROR_INVALID_STATE: return "STTP_ERROR_INVALID_STATE";
57 case STTP_ERROR_INVALID_LANGUAGE: return "STTP_ERROR_INVALID_LANGUAGE";
58 case STTP_ERROR_ENGINE_NOT_FOUND: return "STTP_ERROR_ENGINE_NOT_FOUND";
59 case STTP_ERROR_OPERATION_FAILED: return "STTP_ERROR_OPERATION_FAILED";
60 case STTP_ERROR_NOT_SUPPORTED_FEATURE: return "STTP_ERROR_NOT_SUPPORTED_FEATURE";
62 return "Invalid error code";
66 static sttengine_s* __get_engine(int engine_id)
68 /* check whether engine id is valid or not.*/
70 sttengine_s *engine = NULL;
72 if (g_slist_length(g_engine_list) > 0) {
74 iter = g_slist_nth(g_engine_list, 0);
76 while (NULL != iter) {
77 /*Get handle data from list*/
80 if (engine_id == engine->engine_id) {
85 iter = g_slist_next(iter);
92 /* Register engine id */
93 int stt_engine_load(int engine_id, const char* filepath)
95 if (NULL == filepath || engine_id < 0) {
96 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
97 return STTP_ERROR_INVALID_PARAMETER;
100 sttengine_s* engine = NULL;
101 engine = __get_engine(engine_id);
102 if (NULL != engine) {
103 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is already loaded", engine_id);
107 SECURE_SLOG(LOG_DEBUG, stt_tag(), "[Engine] Load engine id(%d), path(%s)", engine_id, filepath);
109 /* allocation memory */
110 engine = (sttengine_s*)calloc(1, sizeof(sttengine_s));
111 if (NULL == engine) {
112 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
113 return STTP_ERROR_OUT_OF_MEMORY;
119 engine->handle = dlopen(filepath, RTLD_LAZY);
120 if (!engine->handle) {
121 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine] Invalid engine (Fail dlopen) : %s", filepath);
123 return STTP_ERROR_OPERATION_FAILED;
126 engine->pefuncs = (sttpe_funcs_s*)calloc(1, sizeof(sttpe_funcs_s));
127 if (NULL == engine->pefuncs) {
128 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
129 dlclose(engine->handle);
131 return STTP_ERROR_OUT_OF_MEMORY;
133 engine->pdfuncs = (sttpd_funcs_s*)calloc(1, sizeof(sttpd_funcs_s));
134 if (NULL == engine->pdfuncs) {
135 SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to allocate memory");
136 dlclose(engine->handle);
137 free(engine->pefuncs);
139 return STTP_ERROR_OUT_OF_MEMORY;
142 engine->sttp_unload_engine = NULL;
143 engine->sttp_load_engine = NULL;
145 engine->sttp_unload_engine = (int (*)())dlsym(engine->handle, "sttp_unload_engine");
146 if (NULL != (error = dlerror()) || NULL == engine->sttp_unload_engine) {
147 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to link daemon to sttp_unload_engine() : %s", error);
148 dlclose(engine->handle);
149 free(engine->pefuncs);
150 free(engine->pdfuncs);
152 return STTP_ERROR_OPERATION_FAILED;
155 engine->sttp_load_engine = (int (*)(sttpd_funcs_s*, sttpe_funcs_s*))dlsym(engine->handle, "sttp_load_engine");
156 if (NULL != (error = dlerror()) || NULL == engine->sttp_load_engine) {
157 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to link daemon to sttp_load_engine() : %s", error);
158 dlclose(engine->handle);
159 free(engine->pefuncs);
160 free(engine->pdfuncs);
162 return STTP_ERROR_OPERATION_FAILED;
165 engine->engine_id = engine_id;
166 engine->engine_path = strdup(filepath);
168 engine->pdfuncs->version = 1;
169 engine->pdfuncs->size = sizeof(sttpd_funcs_s);
171 int ret = engine->sttp_load_engine(engine->pdfuncs, engine->pefuncs);
173 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail sttp_load_engine() : %s", __stt_get_engine_error_code(ret));
174 dlclose(engine->handle);
175 free(engine->pefuncs);
176 free(engine->pdfuncs);
177 free(engine->engine_path);
182 /* engine error check */
183 if (engine->pefuncs->size != sizeof(sttpe_funcs_s)) {
184 SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine is not valid : function size is not matched");
187 if (NULL == engine->pefuncs->initialize ||
188 NULL == engine->pefuncs->deinitialize ||
189 NULL == engine->pefuncs->foreach_langs ||
190 NULL == engine->pefuncs->is_valid_lang ||
191 NULL == engine->pefuncs->support_silence ||
192 NULL == engine->pefuncs->support_recognition_type ||
193 NULL == engine->pefuncs->get_audio_format ||
194 NULL == engine->pefuncs->set_silence_detection ||
195 NULL == engine->pefuncs->start ||
196 NULL == engine->pefuncs->set_recording ||
197 NULL == engine->pefuncs->stop ||
198 NULL == engine->pefuncs->cancel ||
199 NULL == engine->pefuncs->foreach_result_time)
200 /* Current unused functions
201 NULL == engine->pefuncs->start_file_recognition ||
204 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] The engine functions are NOT valid");
205 dlclose(engine->handle);
206 free(engine->pefuncs);
207 free(engine->pdfuncs);
208 free(engine->engine_path);
211 return STTP_ERROR_OPERATION_FAILED;
214 SLOG(LOG_DEBUG, stt_tag(), "[Engine Success] Load engine : version(%d), size(%d)", engine->pefuncs->version, engine->pefuncs->size);
216 g_engine_list = g_slist_append(g_engine_list, engine);
221 /* Unregister engine id */
222 int stt_engine_unload(int engine_id)
224 sttengine_s* engine = NULL;
225 engine = __get_engine(engine_id);
226 if (NULL == engine) {
227 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
228 return STTP_ERROR_INVALID_PARAMETER;
232 engine->sttp_unload_engine();
233 dlclose(engine->handle);
235 if (NULL != engine->engine_path) free(engine->engine_path);
236 if (NULL != engine->pefuncs) free(engine->pefuncs);
237 if (NULL != engine->pdfuncs) free(engine->pdfuncs);
239 g_engine_list = g_slist_remove(g_engine_list, engine);
247 /* Initialize / Deinitialize */
248 int stt_engine_initialize(int engine_id, sttpe_result_cb result_cb, sttpe_silence_detected_cb silence_cb)
250 if (NULL == result_cb || NULL == silence_cb) {
251 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
252 return STTP_ERROR_INVALID_PARAMETER;
255 sttengine_s* engine = NULL;
256 engine = __get_engine(engine_id);
257 if (NULL == engine) {
258 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
259 return STTP_ERROR_INVALID_PARAMETER;
263 ret = engine->pefuncs->initialize(result_cb, silence_cb);
265 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to initialize : %s", __stt_get_engine_error_code(ret));
271 int stt_engine_deinitialize(int engine_id)
273 sttengine_s* engine = NULL;
274 engine = __get_engine(engine_id);
275 if (NULL == engine) {
276 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
277 return STTP_ERROR_INVALID_PARAMETER;
281 ret = engine->pefuncs->deinitialize();
283 SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] Fail to deinitialize : %s", __stt_get_engine_error_code(ret));
289 static bool __supported_language_cb(const char* language, void* user_data)
291 GSList** lang_list = (GSList**)user_data;
293 if (NULL == language || NULL == lang_list) {
294 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Input parameter is NULL in callback!!!!");
298 char* temp_lang = g_strdup(language);
300 *lang_list = g_slist_append(*lang_list, temp_lang);
306 int stt_engine_get_supported_langs(int engine_id, GSList** lang_list)
308 if (NULL == lang_list) {
309 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
310 return STTP_ERROR_INVALID_PARAMETER;
313 sttengine_s* engine = NULL;
314 engine = __get_engine(engine_id);
315 if (NULL == engine) {
316 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
317 return STTP_ERROR_INVALID_PARAMETER;
321 ret = engine->pefuncs->foreach_langs(__supported_language_cb, (void*)lang_list);
323 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] get language list error : %s", __stt_get_engine_error_code(ret));
329 int stt_engine_is_valid_language(int engine_id, const char* language, bool *is_valid)
331 if (NULL == language || NULL == is_valid) {
332 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
333 return STTP_ERROR_INVALID_PARAMETER;
336 sttengine_s* engine = NULL;
337 engine = __get_engine(engine_id);
338 if (NULL == engine) {
339 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
340 return STTP_ERROR_INVALID_PARAMETER;
344 result = engine->pefuncs->is_valid_lang(language);
351 int stt_engine_set_private_data(int engine_id, const char* key, const char* data)
353 if (NULL == key || NULL == data) {
354 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
355 return STTP_ERROR_INVALID_PARAMETER;
358 sttengine_s* engine = NULL;
359 engine = __get_engine(engine_id);
360 if (NULL == engine) {
361 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
362 return STTP_ERROR_INVALID_PARAMETER;
365 int ret = engine->pefuncs->set_private_data(key, data);
367 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to set private data(%d)", ret);
372 int stt_engine_get_private_data(int engine_id, const char* key, char** data)
374 if (NULL == key || NULL == data) {
375 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
376 return STTP_ERROR_INVALID_PARAMETER;
379 sttengine_s* engine = NULL;
380 engine = __get_engine(engine_id);
381 if (NULL == engine) {
382 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
383 return STTP_ERROR_INVALID_PARAMETER;
387 int ret = engine->pefuncs->get_private_data(key, &temp);
389 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to get private data(%d)", ret);
393 *data = strdup(temp);
395 return STTP_ERROR_NONE;
398 int stt_engine_get_first_language(int engine_id, char** language)
400 if (NULL == language) {
401 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
402 return STTP_ERROR_INVALID_PARAMETER;
405 sttengine_s* engine = NULL;
406 engine = __get_engine(engine_id);
407 if (NULL == engine) {
408 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
409 return STTP_ERROR_INVALID_PARAMETER;
412 GSList* lang_list = NULL;
414 ret = engine->pefuncs->foreach_langs(__supported_language_cb, &lang_list);
416 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] get language list error : %s", __stt_get_engine_error_code(ret));
423 iter = g_slist_nth(lang_list, 0);
427 if (true == engine->pefuncs->is_valid_lang(data)) {
428 *language = strdup(data);
430 ret = STTP_ERROR_OPERATION_FAILED;
434 /* if list have item */
435 if (g_slist_length(lang_list) > 0) {
436 /* Get a first item */
437 iter = g_slist_nth(lang_list, 0);
439 while (NULL != iter) {
445 lang_list = g_slist_remove_link(lang_list, iter);
447 iter = g_slist_nth(lang_list, 0);
454 int stt_engine_support_silence(int engine_id, bool* support)
456 if (NULL == support) {
457 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
458 return STTP_ERROR_INVALID_PARAMETER;
461 sttengine_s* engine = NULL;
462 engine = __get_engine(engine_id);
463 if (NULL == engine) {
464 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
465 return STTP_ERROR_INVALID_PARAMETER;
469 result = engine->pefuncs->support_silence();
476 int stt_engine_need_app_credential(int engine_id, bool* need)
479 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
480 return STTP_ERROR_INVALID_PARAMETER;
483 sttengine_s* engine = NULL;
484 engine = __get_engine(engine_id);
485 if (NULL == engine) {
486 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
487 return STTP_ERROR_INVALID_PARAMETER;
491 if (NULL != engine->pefuncs->need_app_credential) {
492 result = engine->pefuncs->need_app_credential();
494 return STTP_ERROR_NONE;
497 return STTP_ERROR_OPERATION_FAILED;
500 int stt_engine_support_recognition_type(int engine_id, const char* type, bool* support)
502 if (NULL == type || NULL == support) {
503 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
504 return STTP_ERROR_INVALID_PARAMETER;
507 sttengine_s* engine = NULL;
508 engine = __get_engine(engine_id);
509 if (NULL == engine) {
510 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
511 return STTP_ERROR_INVALID_PARAMETER;
515 if (NULL != engine->pefuncs->support_recognition_type) {
516 result = engine->pefuncs->support_recognition_type(type);
521 return STTP_ERROR_OPERATION_FAILED;
524 int stt_engine_get_audio_type(int engine_id, sttp_audio_type_e* types, int* rate, int* channels)
526 if (NULL == types || NULL == rate || NULL == channels) {
527 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
528 return STTP_ERROR_INVALID_PARAMETER;
531 sttengine_s* engine = NULL;
532 engine = __get_engine(engine_id);
533 if (NULL == engine) {
534 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
535 return STTP_ERROR_INVALID_PARAMETER;
539 ret = engine->pefuncs->get_audio_format(types, rate, channels);
541 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to get audio format : %s", __stt_get_engine_error_code(ret));
548 int stt_engine_set_silence_detection(int engine_id, bool value)
550 sttengine_s* engine = NULL;
551 engine = __get_engine(engine_id);
552 if (NULL == engine) {
553 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
554 return STTP_ERROR_INVALID_PARAMETER;
557 int ret = engine->pefuncs->set_silence_detection(value);
558 if (STTP_ERROR_NOT_SUPPORTED_FEATURE == ret) {
559 SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] Not support silence detection");
560 return STTP_ERROR_NOT_SUPPORTED_FEATURE;
561 } else if (0 != ret) {
562 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to set silence detection : %d", ret);
568 int stt_engine_check_app_agreed(int engine_id, const char* appid, bool* value)
570 sttengine_s* engine = NULL;
571 engine = __get_engine(engine_id);
572 if (NULL == engine) {
573 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
574 return STTP_ERROR_INVALID_PARAMETER;
577 if (NULL == engine->pefuncs->check_app_agreed) {
578 SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] Not support app agreement. All app is available");
583 int ret = engine->pefuncs->check_app_agreed(appid, value);
585 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to get app agreement : %s", __stt_get_engine_error_code(ret));
593 int stt_engine_recognize_start(int engine_id, const char* lang, const char* recognition_type, const char* credential, void* user_param)
595 if (NULL == lang || NULL == recognition_type) {
596 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
597 return STTP_ERROR_INVALID_PARAMETER;
600 sttengine_s* engine = NULL;
601 engine = __get_engine(engine_id);
602 if (NULL == engine) {
603 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
604 return STTP_ERROR_INVALID_PARAMETER;
607 int ret = engine->pefuncs->start(lang, recognition_type, credential, user_param);
609 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to start recognition : %s", __stt_get_engine_error_code(ret));
610 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to start recognition : lang(%s), recognition_type(%s), credential(%s)", lang, recognition_type, credential);
616 int stt_engine_set_recording_data(int engine_id, const void* data, unsigned int length)
619 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
620 return STTP_ERROR_INVALID_PARAMETER;
623 sttengine_s* engine = NULL;
624 engine = __get_engine(engine_id);
625 if (NULL == engine) {
626 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
627 return STTP_ERROR_INVALID_PARAMETER;
630 int ret = engine->pefuncs->set_recording(data, length);
632 SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] Fail to set recording : %s", __stt_get_engine_error_code(ret));
638 int stt_engine_recognize_stop(int engine_id)
640 sttengine_s* engine = NULL;
641 engine = __get_engine(engine_id);
642 if (NULL == engine) {
643 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
644 return STTP_ERROR_INVALID_PARAMETER;
647 int ret = engine->pefuncs->stop();
649 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to stop : %s", __stt_get_engine_error_code(ret));
655 int stt_engine_recognize_cancel(int engine_id)
657 sttengine_s* engine = NULL;
658 engine = __get_engine(engine_id);
659 if (NULL == engine) {
660 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
661 return STTP_ERROR_INVALID_PARAMETER;
664 int ret = engine->pefuncs->cancel();
666 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to cancel : %s", __stt_get_engine_error_code(ret));
672 int stt_engine_foreach_result_time(int engine_id, void* time_info, sttpe_result_time_cb callback, void* user_data)
674 sttengine_s* engine = NULL;
675 engine = __get_engine(engine_id);
676 if (NULL == engine) {
677 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
678 return STTP_ERROR_INVALID_PARAMETER;
681 int ret = engine->pefuncs->foreach_result_time(time_info, callback, user_data);
683 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to foreach result time : %s", __stt_get_engine_error_code(ret));
689 int stt_engine_recognize_start_file(int engine_id, const char* lang, const char* recognition_type,
690 const char* filepath, sttp_audio_type_e audio_type, int sample_rate, void* user_param)
692 if (NULL == filepath || NULL == lang || NULL == recognition_type) {
693 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Invalid Parameter");
694 return STTP_ERROR_INVALID_PARAMETER;
697 sttengine_s* engine = NULL;
698 engine = __get_engine(engine_id);
699 if (NULL == engine) {
700 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
701 return STTP_ERROR_INVALID_PARAMETER;
704 if (NULL == engine->pefuncs->start_file) {
705 SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine API is invalid");
706 return STTP_ERROR_NOT_SUPPORTED_FEATURE;
709 int ret = engine->pefuncs->start_file(lang, recognition_type, filepath, audio_type, sample_rate, user_param);
711 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to start file recognition : %s", __stt_get_engine_error_code(ret));
717 int stt_engine_recognize_cancel_file(int engine_id)
719 sttengine_s* engine = NULL;
720 engine = __get_engine(engine_id);
721 if (NULL == engine) {
722 SECURE_SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine id(%d) is invalid", engine_id);
723 return STTP_ERROR_INVALID_PARAMETER;
726 if (NULL == engine->pefuncs->cancel_file) {
727 SLOG(LOG_WARN, stt_tag(), "[Engine WARNING] engine API is invalid");
728 return STTP_ERROR_NOT_SUPPORTED_FEATURE;
731 int ret = engine->pefuncs->cancel_file();
733 SLOG(LOG_ERROR, stt_tag(), "[Engine ERROR] Fail to start file recognition : %s", __stt_get_engine_error_code(ret));