2 * Copyright (c) 2011-2014 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.
16 #include <dlog/dlog.h>
22 #define TAG_STT_TEST "stt_test"
24 static stt_h g_stt = NULL;
26 static Eina_Bool __stt_test_finalize(void *data)
29 SLOG(LOG_DEBUG, TAG_STT_TEST, "Unset callbacks");
30 ret = stt_file_unset_recognition_result_cb();
31 if (STT_FILE_ERROR_NONE != ret) {
32 SLOG(LOG_ERROR, TAG_STT_TEST, "[ERROR] Fail to unset recognition cb");
35 SLOG(LOG_DEBUG, TAG_STT_TEST, "STT file deinitialize");
36 ret = stt_file_deinitialize();
37 if (STT_FILE_ERROR_NONE != ret) {
38 SLOG(LOG_ERROR, TAG_STT_TEST, "[ERROR] Fail to deinitialize");
41 ecore_main_loop_quit();
46 static void __stt_file_state_changed_cb(stt_file_state_e previous, stt_file_state_e current, void* user_data)
50 static bool __stt_file_supported_language_cb(const char* language, void* user_data)
55 SLOG(LOG_DEBUG, TAG_STT_TEST, "=== %s ===", language);
59 static bool __stt_file_result_time_cb(int index, stt_file_result_time_event_e event, const char* text,
60 long start_time, long end_time, void* user_data)
63 SLOG(LOG_DEBUG, TAG_STT_TEST, "[%d] %s - %ld to %ld", index, text, start_time, end_time);
69 static void __stt_file_recognition_result_cb(stt_file_result_event_e event, const char** data, int data_count, const char* msg, void *user_data)
71 SLOG(LOG_DEBUG, TAG_STT_TEST, "==== Result Callback ====");
72 if (STT_FILE_RESULT_EVENT_ERROR == event) {
73 SLOG(LOG_ERROR, TAG_STT_TEST, "[ERROR] Error Result");
74 ecore_timer_add(0, __stt_test_finalize, NULL);
79 SLOG(LOG_DEBUG, TAG_STT_TEST, "( %s )", data[0]);
84 ret = stt_file_foreach_detailed_result(__stt_file_result_time_cb, NULL);
85 if (STT_FILE_ERROR_NONE != ret) {
86 SLOG(LOG_ERROR, TAG_STT_TEST, "[ERROR] Fail to get result time");
89 if (STT_FILE_RESULT_EVENT_FINAL_RESULT == event) {
90 ecore_timer_add(0, __stt_test_finalize, NULL);
96 static bool __supported_engine_cb(const char* engine_id, const char* engine_name, void* user_data)
98 SLOG(LOG_DEBUG, TAG_STT_TEST, "Engine id(%s) name(%s)", engine_id, engine_name);
103 static Eina_Bool __get_engine_list(void *data)
106 SLOG(LOG_DEBUG, TAG_STT_TEST, "STT get engine list");
107 ret = stt_file_foreach_supported_engines(__supported_engine_cb, NULL);
108 if (STT_FILE_ERROR_NONE != ret) {
109 SLOG(LOG_ERROR, TAG_STT_TEST, "Fail to get engine list");
113 SLOG(LOG_DEBUG, TAG_STT_TEST, "STT get engine");
114 ret = stt_file_get_engine(&cur_engine);
115 if (STT_FILE_ERROR_NONE != ret) {
116 SLOG(LOG_ERROR, TAG_STT_TEST, "[ERROR] Fail to get engine");
120 if (NULL != cur_engine) {
121 SLOG(LOG_DEBUG, TAG_STT_TEST, "Current engine - %s", cur_engine);
128 static Eina_Bool __file_start(void *data)
130 char *tmp = (char *)data;
132 SLOG(LOG_DEBUG, TAG_STT_TEST, "STT start file recognition");
133 ret = stt_file_start("en_US", "stt.recognition.type.FREE", tmp, STT_FILE_AUDIO_TYPE_RAW_S16, 16000);
134 if (STT_FILE_ERROR_NONE != ret) {
135 SLOG(LOG_ERROR, TAG_STT_TEST, "[ERROR] Fail to start");
141 static Eina_Bool __stt_start(void *data)
144 SLOG(LOG_DEBUG, TAG_STT_TEST, "STT set silence detection");
145 ret = stt_set_silence_detection(g_stt, STT_OPTION_SILENCE_DETECTION_TRUE);
146 if (STT_ERROR_NONE != ret) {
147 SLOG(LOG_ERROR, TAG_STT_TEST, "[ERROR] Fail to set silence detection");
150 SLOG(LOG_DEBUG, TAG_STT_TEST, "STT start");
151 ret = stt_start(g_stt, "en_US", "stt.recognition.type.FREE");
152 if (STT_ERROR_NONE != ret) {
153 SLOG(LOG_ERROR, TAG_STT_TEST, "[ERROR] Fail to start");
158 static void __stt_state_changed_cb(stt_h stt, stt_state_e previous, stt_state_e current, void* user_data)
160 if (STT_STATE_CREATED == previous && STT_STATE_READY == current) {
161 SLOG(LOG_DEBUG, TAG_STT_TEST, "State is Created -> Ready");
162 ecore_timer_add(0, __stt_start, NULL);
166 static Eina_Bool __stt_finalize(void *data)
169 SLOG(LOG_DEBUG, TAG_STT_TEST, "STT destroy");
170 ret = stt_destroy(g_stt);
171 if (STT_ERROR_NONE != ret) {
172 SLOG(LOG_ERROR, TAG_STT_TEST, "[ERROR] Fail to stt destroy");
175 ecore_main_loop_quit();
179 static void __stt_recognition_result_cb(stt_h stt, stt_result_event_e event, const char** data, int data_count, const char* msg, void *user_data)
181 SLOG(LOG_DEBUG, TAG_STT_TEST, "==== STT result cb ====");
184 SLOG(LOG_DEBUG, TAG_STT_TEST, "( %s )", data[0]);
187 ecore_timer_add(0, __stt_finalize, NULL);
190 int main(int argc, char *argv[])
193 SLOG(LOG_DEBUG, TAG_STT_TEST, "Please check parameter");
194 SLOG(LOG_DEBUG, TAG_STT_TEST, "Ex> stt-test -f <file path>");
195 SLOG(LOG_DEBUG, TAG_STT_TEST, "Ex> stt-test -m");
199 if (strcmp("-f", argv[1]) && strcmp("-m", argv[1])) {
200 SLOG(LOG_DEBUG, TAG_STT_TEST, "Please check parameter");
201 SLOG(LOG_DEBUG, TAG_STT_TEST, "Ex> stt-test -f <file path>");
202 SLOG(LOG_DEBUG, TAG_STT_TEST, "Ex> stt-test -m");
206 if (!strcmp("-f", argv[1])) {
207 if (0 != access(argv[2], F_OK)) {
208 SLOG(LOG_DEBUG, TAG_STT_TEST, "Please check filepath");
212 SLOG(LOG_DEBUG, TAG_STT_TEST, "===== STT File (%s) Sample start =====", argv[2]);
215 SLOG(LOG_ERROR, TAG_STT_TEST, "[Main ERROR] Fail ecore_init()");
220 SLOG(LOG_DEBUG, TAG_STT_TEST, "STT File initialize");
221 ret = stt_file_initialize();
222 if (STT_FILE_ERROR_NONE != ret) {
223 SLOG(LOG_ERROR, TAG_STT_TEST, "Fail to initialize");
227 SLOG(LOG_DEBUG, TAG_STT_TEST, "STT Set Callbacks");
228 ret = stt_file_set_recognition_result_cb(__stt_file_recognition_result_cb, NULL);
229 if (STT_FILE_ERROR_NONE != ret) {
230 SLOG(LOG_ERROR, TAG_STT_TEST, "Fail to set recognition result cb");
234 ret = stt_file_set_state_changed_cb(__stt_file_state_changed_cb, NULL);
235 if (STT_FILE_ERROR_NONE != ret) {
236 SLOG(LOG_ERROR, TAG_STT_TEST, "Fail to set state changed cb");
240 SLOG(LOG_DEBUG, TAG_STT_TEST, "Get supported langauge");
241 ret = stt_file_foreach_supported_languages(__stt_file_supported_language_cb, NULL);
242 if (STT_FILE_ERROR_NONE != ret) {
243 SLOG(LOG_ERROR, TAG_STT_TEST, "Fail to get supported language");
247 ecore_timer_add(1, __get_engine_list, NULL);
249 char *tmp = strdup(argv[2]);
250 ecore_timer_add(1, __file_start, tmp);
251 } else if (!strcmp("-m", argv[1])) {
257 SLOG(LOG_DEBUG, TAG_STT_TEST, "STT Create");
258 ret = stt_create(&g_stt);
259 if (STT_ERROR_NONE != ret) {
260 SLOG(LOG_ERROR, TAG_STT_TEST, "Fail to create");
264 SLOG(LOG_DEBUG, TAG_STT_TEST, "Set callback");
265 ret = stt_set_state_changed_cb(g_stt, __stt_state_changed_cb, NULL);
266 if (STT_ERROR_NONE != ret) {
268 SLOG(LOG_ERROR, TAG_STT_TEST, "Fail to set state changed cb");
271 ret = stt_set_recognition_result_cb(g_stt, __stt_recognition_result_cb, NULL);
272 if (STT_ERROR_NONE != ret) {
274 SLOG(LOG_ERROR, TAG_STT_TEST, "Fail to set recognition result cb");
278 SLOG(LOG_DEBUG, TAG_STT_TEST, "STT prepare");
279 ret = stt_prepare(g_stt);
280 if (STT_ERROR_NONE != ret) {
282 SLOG(LOG_ERROR, TAG_STT_TEST, "Fail to prepare");
287 ecore_main_loop_begin();
291 SLOG(LOG_DEBUG, TAG_STT_TEST, "===== STT END =====");