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.
18 #include "stt_engine.h"
20 #include "stt_network.h"
21 #include "sttd_dbus.h"
22 #include "sttd_server.h"
23 #include "sttd_engine_agent.h"
27 static bool __is_default_engine()
30 engine = vconf_get_str(VCONFKEY_STT_ENGINE_DEFAULT);
32 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get sting for stt engine");
36 char appid[1024] = {'\0', };
37 if (0 != aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1)) {
38 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to get callee appid by pid");
41 SLOG(LOG_DEBUG, TAG_STTD, "[Server] STT Default Engine(%s), appId(%s)", engine, appid);
42 if (0 == strncmp(engine, appid, strlen(engine))) {
50 int stte_main(int argc, char**argv, stte_request_callback_s *callback)
52 SLOG(LOG_DEBUG, TAG_STTD, "===== Start engine");
54 int ret = STTE_ERROR_NONE;
57 SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to initialize Ecore");
58 return STTE_ERROR_OPERATION_FAILED;
61 if (TRUE == __is_default_engine()) {
62 if (0 != sttd_dbus_open_connection()) {
63 SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to open connection");
65 return STTE_ERROR_OPERATION_FAILED;
69 ret = sttd_initialize(callback);
71 SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to initialize stt-service");
72 sttd_dbus_close_connection();
77 stt_network_initialize();
79 SLOG(LOG_DEBUG, TAG_STTD, "[Main] stt-service start...");
81 SLOG(LOG_DEBUG, TAG_STTD, "=====");
82 SLOG(LOG_DEBUG, TAG_STTD, " ");
83 SLOG(LOG_DEBUG, TAG_STTD, " ");
85 return STTE_ERROR_NONE;
88 int stte_send_result(stte_result_event_e event, const char* type, const char** result, int result_count,
89 const char* msg, void* time_info, void* user_data)
91 if (NULL == type || NULL == result) {
92 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Invalid parameter");
95 int ret = STTE_ERROR_NONE;
96 stt_engine_result_cb result_cb = NULL;
97 ret = stt_engine_get_recognition_result_cb(&result_cb);
98 if (STTE_ERROR_NONE == ret && NULL != result_cb) {
99 ret = result_cb(event, type, result, result_count, msg, time_info, user_data);
101 ret = sttd_engine_agent_send_result(event, type, result, result_count, msg, time_info, user_data);
104 if (STTE_ERROR_NONE != ret) {
105 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send result");
110 int stte_send_error(stte_error_e error, const char* msg)
112 int ret = STTE_ERROR_NONE;
113 ret = sttd_engine_agent_send_error(error, msg);
115 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info");
120 int stte_send_speech_status(stte_speech_status_e status, void* user_data)
122 int ret = STTE_ERROR_NONE;
123 ret = sttd_engine_agent_send_speech_status(status, user_data);
125 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send speech status");
130 int stte_set_private_data_set_cb(stte_private_data_set_cb callback)
132 int ret = STTE_ERROR_NONE;
133 ret = stt_engine_set_private_data_set_cb(callback, NULL);
135 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set private data set callback");
140 int stte_set_private_data_requested_cb(stte_private_data_requested_cb callback)
142 int ret = STTE_ERROR_NONE;
143 ret = stt_engine_set_private_data_requested_cb(callback, NULL);
145 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set private data requested callback");
150 int stte_set_audio_type_set_cb(stte_audio_type_cb callback, void* user_data)
152 SLOG(LOG_INFO, TAG_STTD, "[Server Info] Set audio type set callback");
154 int ret = STTE_ERROR_NONE;
155 ret = stt_engine_set_audio_type_set_cb(callback, user_data);
157 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to set audio type set");
162 int stte_unset_audio_type_set_cb(void)
164 SLOG(LOG_INFO, TAG_STTD, "[Server Info] Unset audio type set callback");
166 int ret = STTE_ERROR_NONE;
167 ret = stt_engine_unset_audio_type_set_cb();
169 SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to unset audio type set");