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.
14 #include <sound_manager.h>
15 #include "sttd_main.h"
16 #include "sttd_server.h"
18 #include "sttd_client_data.h"
19 #include "sttd_engine_agent.h"
20 #include "sttd_config.h"
21 #include "sttd_recorder.h"
22 #include "sttd_network.h"
23 #include "sttd_dbus.h"
26 * STT Server static variable
28 static bool g_is_engine;
30 static double g_state_check_time = 15.5;
33 * STT Server Callback Functions ` *
36 Eina_Bool __stop_by_silence(void *data)
38 SLOG(LOG_DEBUG, TAG_STTD, "===== Stop by silence detection");
42 uid = sttd_client_get_current_recording();
45 if (0 != sttd_server_stop(uid))
48 int ret = sttdc_send_set_state(uid, (int)APP_STATE_PROCESSING);
50 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send state : result(%d)", ret);
53 sttd_server_finalize(uid);
57 SLOG(LOG_DEBUG, TAG_STTD, "=====");
58 SLOG(LOG_DEBUG, TAG_STTD, " ");
63 int audio_recorder_callback(const void* data, const unsigned int length)
65 if (0 != sttd_engine_recognize_audio(data, length)) {
66 int uid = sttd_client_get_current_recording();
69 if (0 != sttd_client_get_state(uid, &state)) {
70 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is not valid ");
74 if (APP_STATE_RECORDING != state) {
75 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current state is not recording");
79 ecore_timer_add(0, __stop_by_silence, NULL);
87 void sttd_server_recognition_result_callback(sttp_result_event_e event, const char* type,
88 const char** data, int data_count, const char* msg, void *user_data)
90 SLOG(LOG_DEBUG, TAG_STTD, "===== Recognition Result Callback");
92 if (NULL == user_data) {
93 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] user data is NULL");
94 SLOG(LOG_DEBUG, TAG_STTD, "=====");
95 SLOG(LOG_DEBUG, TAG_STTD, " ");
100 int *uid = (int*)user_data;
102 SLOG(LOG_DEBUG, TAG_STTD, "[Server] uid (%d), event(%d)", *uid, event);
105 if (0 != sttd_client_get_state(*uid, &state)) {
106 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid ");
107 SLOG(LOG_DEBUG, TAG_STTD, "=====");
108 SLOG(LOG_DEBUG, TAG_STTD, " ");
112 /* Delete timer for processing time out */
114 sttd_cliet_get_timer(*uid, &timer);
117 ecore_timer_del(timer);
119 /* send result to client */
120 if (STTP_RESULT_EVENT_SUCCESS == event && 0 < data_count && NULL != data) {
122 if (APP_STATE_PROCESSING == state ) {
123 SLOG(LOG_DEBUG, TAG_STTD, "[Server] the size of result from engine is '%d' %s", data_count);
125 if (0 != sttdc_send_result(*uid, type, data, data_count, msg)) {
126 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send result");
127 int reason = (int)STTD_ERROR_OPERATION_FAILED;
129 if (0 != sttdc_send_error_signal(*uid, reason, "Fail to send recognition result")) {
130 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info . Remove client data");
134 SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] Current state is NOT thinking.");
136 } else if (STTP_RESULT_EVENT_NO_RESULT == event || STTP_RESULT_EVENT_ERROR == event) {
138 if (APP_STATE_PROCESSING == state ) {
139 if (0 != sttdc_send_result(*uid, type, NULL, 0, msg)) {
140 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send result ");
143 int reason = (int)STTD_ERROR_INVALID_STATE;
144 if (0 != sttdc_send_error_signal(*uid, reason, "[ERROR] Fail to send recognition result")) {
145 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info ");
149 SLOG(LOG_WARN, TAG_STTD, "[Server ERROR] Current state is NOT thinking.");
155 /* change state of uid */
156 sttd_client_set_state(*uid, APP_STATE_READY);
158 if (NULL != user_data)
161 SLOG(LOG_DEBUG, TAG_STTD, "=====");
162 SLOG(LOG_DEBUG, TAG_STTD, " ");
167 void sttd_server_partial_result_callback(sttp_result_event_e event, const char* data, void *user_data)
169 SLOG(LOG_DEBUG, TAG_STTD, "===== Partial Result Callback");
172 int *uid = (int*)user_data;
174 SLOG(LOG_DEBUG, TAG_STTD, "[Server] uid (%d), event(%d)", uid, event);
177 if (0 != sttd_client_get_state(*uid, &state)) {
178 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid ");
179 SLOG(LOG_DEBUG, TAG_STTD, "=====");
180 SLOG(LOG_DEBUG, TAG_STTD, " ");
184 /* send result to client */
185 if (STTP_RESULT_EVENT_SUCCESS == event && NULL != data) {
186 if (0 != sttdc_send_partial_result(*uid, data)) {
187 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send partial result");
191 SLOG(LOG_DEBUG, TAG_STTD, "=====");
192 SLOG(LOG_DEBUG, TAG_STTD, " ");
195 void sttd_server_silence_dectection_callback(void *user_param)
197 SLOG(LOG_DEBUG, TAG_STTD, "===== Silence Detection Callback");
199 int uid = sttd_client_get_current_recording();
202 if (0 != sttd_client_get_state(uid, &state)) {
203 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is not valid ");
207 if (APP_STATE_RECORDING != state) {
208 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current state is not recording");
212 ecore_timer_add(0, __stop_by_silence, NULL);
214 SLOG(LOG_DEBUG, TAG_STTD, "=====");
215 SLOG(LOG_DEBUG, TAG_STTD, " ");
224 int sttd_initialize()
228 if (sttd_config_initialize()) {
229 SLOG(LOG_ERROR, TAG_STTD, "[Server WARNING] Fail to initialize config.");
232 /* Engine Agent initialize */
233 ret = sttd_engine_agent_init(sttd_server_recognition_result_callback, sttd_server_partial_result_callback,
234 sttd_server_silence_dectection_callback);
236 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to engine agent initialize : result(%d)", ret);
240 if (0 != sttd_engine_agent_initialize_current_engine()) {
241 SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] There is No STT-Engine !!!!!");
247 /* Set audio session */
248 ret = sound_manager_set_session_type(SOUND_SESSION_TYPE_EXCLUSIVE);
249 if (SOUND_MANAGER_ERROR_NONE != ret) {
250 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set sound session : result(%d)", ret);
251 return STTD_ERROR_OPERATION_FAILED;
254 SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] initialize");
261 sttd_config_finalize();
263 sttd_engine_agent_release();
265 return STTD_ERROR_NONE;
268 Eina_Bool sttd_cleanup_client(void *data)
270 int* client_list = NULL;
271 int client_count = 0;
273 if (0 != sttd_client_get_list(&client_list, &client_count))
276 if (NULL == client_list)
282 SLOG(LOG_DEBUG, TAG_STTD, "===== Clean up client ");
284 for (i = 0;i < client_count;i++) {
285 result = sttdc_send_hello(client_list[i]);
288 SLOG(LOG_DEBUG, TAG_STTD, "[Server] uid(%d) should be removed.", client_list[i]);
289 sttd_server_finalize(client_list[i]);
290 } else if (-1 == result) {
291 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Hello result has error");
295 SLOG(LOG_DEBUG, TAG_STTD, "=====");
296 SLOG(LOG_DEBUG, TAG_STTD, " ");
304 * STT Server Functions for Client
307 int sttd_server_initialize(int pid, int uid, bool* silence, bool* profanity, bool* punctuation)
309 if (false == g_is_engine) {
310 if (0 != sttd_engine_agent_initialize_current_engine()) {
311 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] No Engine");
313 return STTD_ERROR_ENGINE_NOT_FOUND;
319 /* check if uid is valid */
321 if (0 == sttd_client_get_state(uid, &state)) {
322 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid has already been registered");
323 return STTD_ERROR_INVALID_PARAMETER;
326 /* load if engine is unloaded */
327 if (0 == sttd_client_get_ref_count()) {
328 if (0 != sttd_engine_agent_load_current_engine()) {
329 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to load current engine");
330 return STTD_ERROR_OPERATION_FAILED;
333 /* set type, channel, sample rate */
334 sttp_audio_type_e atype;
338 if (0 != sttd_engine_get_audio_format(&atype, &rate, &channels)) {
339 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get audio format of engine.");
340 return STTD_ERROR_OPERATION_FAILED;
343 if (0 != sttd_recorder_create(audio_recorder_callback, atype, channels, rate)) {
344 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set recorder");
345 return STTD_ERROR_OPERATION_FAILED;
348 SLOG(LOG_DEBUG, TAG_STTD, "[Server] audio type(%d), channel(%d)", (int)atype, (int)channels);
351 /* Add client information to client manager */
352 if (0 != sttd_client_add(pid, uid)) {
353 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to add client info");
354 return STTD_ERROR_OPERATION_FAILED;
357 if (0 != sttd_engine_get_option_supported(silence, profanity, punctuation)) {
358 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine options supported");
359 return STTD_ERROR_OPERATION_FAILED;
362 SLOG(LOG_DEBUG, TAG_STTD, "[Server Success] Initialize");
364 return STTD_ERROR_NONE;
367 static Eina_Bool __quit_ecore_loop(void *data)
369 ecore_main_loop_quit();
370 SLOG(LOG_DEBUG, TAG_STTD, "[Server] quit ecore main loop");
374 int sttd_server_finalize(int uid)
376 /* check if uid is valid */
378 if (0 != sttd_client_get_state(uid, &state)) {
379 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid ");
380 return STTD_ERROR_INVALID_PARAMETER;
383 /* release recorder */
384 if (APP_STATE_RECORDING == state || APP_STATE_PROCESSING == state) {
385 sttd_recorder_stop();
386 sttd_engine_recognize_cancel();
389 /* Remove client information */
390 if (0 != sttd_client_delete(uid)) {
391 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to delete client");
394 /* unload engine, if ref count of client is 0 */
395 if (0 == sttd_client_get_ref_count()) {
396 sttd_recorder_destroy();
398 ecore_timer_add(0, __quit_ecore_loop, NULL);
401 return STTD_ERROR_NONE;
404 int sttd_server_get_supported_languages(int uid, GList** lang_list)
406 /* check if uid is valid */
408 if (0 != sttd_client_get_state(uid, &state)) {
409 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid ");
410 return STTD_ERROR_INVALID_PARAMETER;
413 /* get language list from engine */
414 int ret = sttd_engine_supported_langs(lang_list);
416 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get supported languages");
417 return STTD_ERROR_OPERATION_FAILED;
420 SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] sttd_server_get_supported_languages");
422 return STTD_ERROR_NONE;
425 int sttd_server_get_current_langauage(int uid, char** current_lang)
427 /* check if uid is valid */
429 if (0 != sttd_client_get_state(uid, &state)) {
430 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid ");
431 return STTD_ERROR_INVALID_PARAMETER;
434 if (NULL == current_lang) {
435 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL");
436 return STTD_ERROR_INVALID_PARAMETER;
439 /*get current language from engine */
440 int ret = sttd_engine_get_default_lang(current_lang);
442 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get default language :result(%d)", ret);
443 return STTD_ERROR_OPERATION_FAILED;
446 SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] sttd_engine_get_default_lang");
448 return STTD_ERROR_NONE;
451 int sttd_server_is_partial_result_supported(int uid, int* partial_result)
453 /* check if uid is valid */
455 if (0 != sttd_client_get_state(uid, &state)) {
456 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid ");
457 return STTD_ERROR_INVALID_PARAMETER;
460 if (NULL == partial_result) {
461 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL");
462 return STTD_ERROR_INVALID_PARAMETER;
466 int ret = sttd_engine_is_partial_result_supported(&temp);
468 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get partial result supported : result(%d)", ret);
469 return STTD_ERROR_OPERATION_FAILED;
472 SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Partial result supporting is %s", temp ? "true" : "false");
474 return STTD_ERROR_NONE;
477 Eina_Bool __check_recording_state(void *data)
480 int uid = sttd_client_get_current_recording();
485 if (0 != sttdc_send_get_state(uid, (int*)&state)) {
486 /* client is removed */
487 SLOG(LOG_DEBUG, TAG_STTD, "[Server] uid(%d) should be removed.", uid);
488 sttd_server_finalize(uid);
492 if (APP_STATE_READY == state) {
494 SLOG(LOG_DEBUG, TAG_STTD, "[Server] The state of uid(%d) is 'Ready'. The daemon should cancel recording", uid);
495 sttd_server_cancel(uid);
496 } else if (APP_STATE_PROCESSING == state) {
497 /* Cancel stt and send change state */
498 SLOG(LOG_DEBUG, TAG_STTD, "[Server] The state of uid(%d) is 'Processing'. The daemon should cancel recording", uid);
499 sttd_server_cancel(uid);
500 sttdc_send_set_state(uid, (int)APP_STATE_READY);
503 SLOG(LOG_DEBUG, TAG_STTD, "[Server] The states of daemon and client are identical");
510 int sttd_server_start(int uid, const char* lang, const char* recognition_type,
511 int profanity, int punctuation, int silence)
513 /* check if uid is valid */
515 if (0 != sttd_client_get_state(uid, &state)) {
516 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid ");
517 return STTD_ERROR_INVALID_PARAMETER;
520 /* check uid state */
521 if (APP_STATE_READY != state) {
522 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] sttd_server_start : current state is not ready");
523 return STTD_ERROR_INVALID_STATE;
526 if (0 < sttd_client_get_current_recording()) {
527 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current STT Engine is busy because of recording");
528 return STTD_ERROR_RECORDER_BUSY;
531 if (0 < sttd_client_get_current_thinking()) {
532 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current STT Engine is busy because of thinking");
533 return STTD_ERROR_RECORDER_BUSY;
536 /* check if engine use network */
537 if (true == sttd_engine_agent_need_network()) {
538 if (false == sttd_network_is_connected()) {
539 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Disconnect network. Current engine needs to network connection.");
540 return STTD_ERROR_OUT_OF_NETWORK;
544 /* engine start recognition */
546 user_data = (int*)malloc( sizeof(int) * 1);
548 /* free on result callback */
551 SLOG(LOG_DEBUG, TAG_STTD, "[Server] start : uid(%d), lang(%s), recog_type(%s)", *user_data, lang, recognition_type );
553 int ret = sttd_engine_recognize_start((char*)lang, recognition_type, profanity, punctuation, silence, (void*)user_data);
555 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to start recognition : result(%d)", ret);
556 return STTD_ERROR_OPERATION_FAILED;
560 ret = sttd_recorder_start();
562 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to start recorder : result(%d)", ret);
563 sttd_engine_recognize_cancel();
564 return STTD_ERROR_OPERATION_FAILED;
567 SLOG(LOG_DEBUG, TAG_STTD, "[Server] start recording");
569 /* change uid state */
570 sttd_client_set_state(uid, APP_STATE_RECORDING);
572 Ecore_Timer* timer = ecore_timer_add(g_state_check_time, __check_recording_state, NULL);
573 sttd_cliet_set_timer(uid, timer);
575 return STTD_ERROR_NONE;
578 Eina_Bool __time_out_for_processing(void *data)
581 int uid = sttd_client_get_current_thinking();
586 int ret = sttd_engine_recognize_cancel();
588 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel : result(%d)", ret);
591 if (0 != sttdc_send_result(uid, STTP_RECOGNITION_TYPE_FREE, NULL, 0, "Time out not to receive recognition result.")) {
592 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send result ");
595 int reason = (int)STTD_ERROR_TIMED_OUT;
596 if (0 != sttdc_send_error_signal(uid, reason, "[ERROR] Fail to send recognition result")) {
597 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info ");
601 /* Change uid state */
602 sttd_client_set_state(uid, APP_STATE_READY);
608 int sttd_server_stop(int uid)
610 /* check if uid is valid */
612 if (0 != sttd_client_get_state(uid, &state)) {
613 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid ");
614 return STTD_ERROR_INVALID_PARAMETER;
617 /* check uid state */
618 if (APP_STATE_RECORDING != state) {
619 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current state is not recording");
620 return STTD_ERROR_INVALID_STATE;
624 sttd_recorder_stop();
626 /* stop engine recognition */
627 int ret = sttd_engine_recognize_stop();
629 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to stop : result(%d)", ret);
630 sttd_client_set_state(uid, APP_STATE_READY);
632 return STTD_ERROR_OPERATION_FAILED;
636 sttd_cliet_get_timer(uid, &timer);
639 ecore_timer_del(timer);
641 /* change uid state */
642 sttd_client_set_state(uid, APP_STATE_PROCESSING);
644 timer = ecore_timer_add(g_state_check_time, __time_out_for_processing, NULL);
645 sttd_cliet_set_timer(uid, timer);
647 return STTD_ERROR_NONE;
650 int sttd_server_cancel(int uid)
652 /* check if uid is valid */
654 if (0 != sttd_client_get_state(uid, &state)) {
655 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid ");
656 return STTD_ERROR_INVALID_PARAMETER;
659 /* check uid state */
660 if (APP_STATE_READY == state) {
661 SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] Current state is ready");
662 return STTD_ERROR_INVALID_STATE;
666 if (APP_STATE_RECORDING == state)
667 sttd_recorder_stop();
669 /* cancel engine recognition */
670 int ret = sttd_engine_recognize_cancel();
672 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel : result(%d)", ret);
673 return STTD_ERROR_OPERATION_FAILED;
677 sttd_cliet_get_timer(uid, &timer);
678 ecore_timer_del(timer);
680 /* change uid state */
681 sttd_client_set_state(uid, APP_STATE_READY);
683 return STTD_ERROR_NONE;
686 int sttd_server_start_file_recognition(int uid, const char* filepath, const char* lang, const char* type,
687 int profanity, int punctuation)
689 /* check if uid is valid */
691 if (0 != sttd_client_get_state(uid, &state)) {
692 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid ");
693 return STTD_ERROR_INVALID_PARAMETER;
696 /* check uid state */
697 if (APP_STATE_READY != state) {
698 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current state is not ready");
699 return STTD_ERROR_INVALID_STATE;
702 if (0 < sttd_client_get_current_recording()) {
703 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current STT Engine is busy because of recording");
704 return STTD_ERROR_RECORDER_BUSY;
707 if (0 < sttd_client_get_current_thinking()) {
708 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current STT Engine is busy because of thinking");
709 return STTD_ERROR_RECORDER_BUSY;
712 /* check if engine use network */
713 if (true == sttd_engine_agent_need_network()) {
714 if (false == sttd_network_is_connected()) {
715 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Disconnect network. Current engine needs to network connection.");
716 return STTD_ERROR_OUT_OF_NETWORK;
720 /* engine start recognition */
722 user_data = (int*)malloc( sizeof(int) * 1);
724 /* free on result callback */
727 SLOG(LOG_DEBUG, TAG_STTD, "[Server] start file recognition : uid(%d), filepath(%s), lang(%s), recog_type(%s)",
728 *user_data, filepath, lang, type );
730 int ret = sttd_engine_recognize_start_file(filepath, (char*)lang, type, profanity, punctuation, (void*)user_data);
732 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to start recognition : result(%d)", ret);
733 return STTD_ERROR_OPERATION_FAILED;
736 SLOG(LOG_DEBUG, TAG_STTD, "[Server] start file recognition");
739 sttd_cliet_get_timer(uid, &timer);
742 ecore_timer_del(timer);
744 /* change uid state */
745 sttd_client_set_state(uid, APP_STATE_PROCESSING);
747 timer = ecore_timer_add(g_state_check_time, __time_out_for_processing, NULL);
748 sttd_cliet_set_timer(uid, timer);
750 return STTD_ERROR_NONE;
753 /******************************************************************************************
754 * STT Server Functions for setting
755 *******************************************************************************************/
757 int sttd_server_setting_initialize(int pid)
759 if (false == g_is_engine) {
760 if (0 != sttd_engine_agent_initialize_current_engine()) {
761 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] No Engine");
763 return STTD_ERROR_ENGINE_NOT_FOUND;
769 /* check whether pid is valid */
770 if (true == sttd_setting_client_is(pid)) {
771 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid ");
772 return STTD_ERROR_INVALID_PARAMETER;
775 /* load if engine is unloaded */
776 if (0 == sttd_client_get_ref_count()) {
777 if (0 != sttd_engine_agent_load_current_engine()) {
778 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to load current engine");
779 return STTD_ERROR_OPERATION_FAILED;
782 /* set type, channel, sample rate */
783 sttp_audio_type_e atype;
787 if (0 != sttd_engine_get_audio_format(&atype, &rate, &channels)) {
788 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get audio format of engine.");
789 return STTD_ERROR_OPERATION_FAILED;
792 if (0 != sttd_recorder_create(audio_recorder_callback, atype, channels, rate)) {
793 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set recorder");
794 return STTD_ERROR_OPERATION_FAILED;
797 SLOG(LOG_DEBUG, TAG_STTD, "[Server] audio type(%d), channel(%d)", (int)atype, (int)channels);
800 /* Add setting client information to client manager (For internal use) */
801 if (0 != sttd_setting_client_add(pid)) {
802 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to add setting client");
803 return STTD_ERROR_OPERATION_FAILED;
806 return STTD_ERROR_NONE;
809 int sttd_server_setting_finalize(int pid)
811 /* Remove client information */
812 if (0 != sttd_setting_client_delete(pid)) {
813 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to delete setting client");
816 /* unload engine, if ref count of client is 0 */
817 if (0 == sttd_client_get_ref_count()) {
818 sttd_recorder_destroy();
820 ecore_timer_add(0, __quit_ecore_loop, NULL);
823 return STTD_ERROR_NONE;
826 int sttd_server_setting_get_engine_list(int pid, GList** engine_list)
828 /* check whether pid is valid */
829 if (true != sttd_setting_client_is(pid)) {
830 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid ");
831 return STTD_ERROR_INVALID_PARAMETER;
834 if (NULL == engine_list) {
835 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL");
836 return STTD_ERROR_INVALID_PARAMETER;
839 int ret = sttd_engine_setting_get_engine_list(engine_list);
841 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine list : result(%d)", ret);
845 return STTD_ERROR_NONE;
848 int sttd_server_setting_get_engine(int pid, char** engine_id)
850 /* check whether pid is valid */
851 if (true != sttd_setting_client_is(pid)) {
852 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid ");
853 return STTD_ERROR_INVALID_PARAMETER;
856 if (NULL == engine_id) {
857 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL");
858 return STTD_ERROR_INVALID_PARAMETER;
862 int ret = sttd_engine_setting_get_engine(engine_id);
864 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine : result(%d)", ret);
868 return STTD_ERROR_NONE;
871 int sttd_server_setting_set_engine(int pid, const char* engine_id)
873 /* check whether pid is valid */
874 if (true != sttd_setting_client_is(pid)) {
875 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid ");
876 return STTD_ERROR_INVALID_PARAMETER;
879 if (NULL == engine_id) {
880 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL");
881 return STTD_ERROR_INVALID_PARAMETER;
885 int ret = sttd_engine_setting_set_engine(engine_id);
887 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set engine : result(%d)", ret);
891 return STTD_ERROR_NONE;
894 int sttd_server_setting_get_lang_list(int pid, char** engine_id, GList** lang_list)
896 /* check whether pid is valid */
897 if (true != sttd_setting_client_is(pid)) {
898 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid ");
899 return STTD_ERROR_INVALID_PARAMETER;
902 if (NULL == lang_list) {
903 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] language is NULL");
904 return STTD_ERROR_INVALID_PARAMETER;
907 int ret = sttd_engine_setting_get_lang_list(engine_id, lang_list);
909 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get language list : result(%d)", ret);
913 return STTD_ERROR_NONE;
916 int sttd_server_setting_get_default_language(int pid, char** language)
918 /* check whether pid is valid */
919 if (true != sttd_setting_client_is(pid)) {
920 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid ");
921 return STTD_ERROR_INVALID_PARAMETER;
924 if (NULL == language) {
925 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] language is NULL");
926 return STTD_ERROR_INVALID_PARAMETER;
929 int ret = sttd_engine_setting_get_default_lang(language);
931 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get default language : result(%d)", ret);
935 return STTD_ERROR_NONE;
938 int sttd_server_setting_set_default_language(int pid, const char* language)
940 /* check whether pid is valid */
941 if (true != sttd_setting_client_is(pid)) {
942 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid ");
943 return STTD_ERROR_INVALID_PARAMETER;
946 if (NULL == language) {
947 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] language is NULL");
948 return STTD_ERROR_INVALID_PARAMETER;
951 int ret = sttd_engine_setting_set_default_lang((char*)language);
953 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set default lang : result(%d)", ret);
957 return STTD_ERROR_NONE;
960 int sttd_server_setting_get_profanity_filter(int pid, bool* value)
962 /* check whether pid is valid */
963 if (true != sttd_setting_client_is(pid)) {
964 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid ");
965 return STTD_ERROR_INVALID_PARAMETER;
969 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL");
970 return STTD_ERROR_INVALID_PARAMETER;
974 ret = sttd_engine_setting_get_profanity_filter(value);
976 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get profanity filter : result(%d)", ret);
980 return STTD_ERROR_NONE;
983 int sttd_server_setting_set_profanity_filter(int pid, bool value)
985 /* check whether pid is valid */
986 if (true != sttd_setting_client_is(pid)) {
987 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid ");
988 return STTD_ERROR_INVALID_PARAMETER;
992 ret = sttd_engine_setting_set_profanity_filter(value);
994 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set profanity filter: result(%d)", ret);
998 return STTD_ERROR_NONE;
1001 int sttd_server_setting_get_punctuation_override(int pid, bool* value)
1003 /* check whether pid is valid */
1004 if (true != sttd_setting_client_is(pid)) {
1005 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid ");
1006 return STTD_ERROR_INVALID_PARAMETER;
1009 if (NULL == value) {
1010 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL");
1011 return STTD_ERROR_INVALID_PARAMETER;
1015 ret = sttd_engine_setting_get_punctuation_override(value);
1017 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get punctuation override : result(%d)", ret);
1021 return STTD_ERROR_NONE;
1024 int sttd_server_setting_set_punctuation_override(int pid, bool value)
1026 /* check whether pid is valid */
1027 if (true != sttd_setting_client_is(pid)) {
1028 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid ");
1029 return STTD_ERROR_INVALID_PARAMETER;
1033 ret = sttd_engine_setting_set_punctuation_override(value);
1035 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set punctuation override : result(%d)", ret);
1039 return STTD_ERROR_NONE;
1042 int sttd_server_setting_get_silence_detection(int pid, bool* value)
1044 /* check whether pid is valid */
1045 if (true != sttd_setting_client_is(pid)) {
1046 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid ");
1047 return STTD_ERROR_INVALID_PARAMETER;
1050 if (NULL == value) {
1051 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Input parameter is NULL");
1052 return STTD_ERROR_INVALID_PARAMETER;
1056 ret = sttd_engine_setting_get_silence_detection(value);
1058 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get silence detection : result(%d)", ret);
1062 return STTD_ERROR_NONE;
1065 int sttd_server_setting_set_silence_detection(int pid, bool value)
1067 /* check whether pid is valid */
1068 if (true != sttd_setting_client_is(pid)) {
1069 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid ");
1070 return STTD_ERROR_INVALID_PARAMETER;
1074 ret = sttd_engine_setting_set_silence_detection(value);
1076 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to Result(%d)", ret);
1080 return STTD_ERROR_NONE;
1083 int sttd_server_setting_get_engine_setting(int pid, char** engine_id, GList** lang_list)
1085 /* check whether pid is valid */
1086 if (true != sttd_setting_client_is(pid)) {
1087 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid ");
1088 return STTD_ERROR_INVALID_PARAMETER;
1091 if (0 != sttd_engine_setting_get_engine_setting_info(engine_id, lang_list)) {
1092 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get engine setting info");
1093 return STTD_ERROR_OPERATION_FAILED;
1096 return STTD_ERROR_NONE;
1099 int sttd_server_setting_set_engine_setting(int pid, const char* key, const char* value)
1101 /* check whether pid is valid */
1102 if (true != sttd_setting_client_is(pid)) {
1103 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Setting pid is NOT valid ");
1104 return STTD_ERROR_INVALID_PARAMETER;
1107 if (0 != sttd_engine_setting_set_engine_setting(key, value)) {
1108 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set engine setting info");
1109 return STTD_ERROR_OPERATION_FAILED;
1112 return STTD_ERROR_NONE;