2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <Elementary.h>
23 #include <wav_player.h>
24 #include <vconf-internal-keys.h>
27 #include "w-input-selector.h"
28 #include "w-input-stt-voice.h"
29 #include "w-input-stt-engine.h"
41 static stt_state_e static_current_stt_state = STT_STATE_CREATED;
44 static void _on_state_change_cb(stt_h stt, stt_state_e previous, stt_state_e current, void* voice_data);
45 static void _on_error_cb(stt_h stt, stt_error_e reason, void *voice_data);
46 static void _on_result_cb(stt_h stt, stt_result_event_e event, const char** data, int data_count, const char* msg, void *voice_data);
48 static bool is_auto_spacing(void *voice_data)
50 VoiceData *voicedata = (VoiceData *)voice_data;
51 int lang = 0, ret = 0;
53 ret = preference_get_int(PREFERENCE_ISE_STT_LANGUAGE, &lang);
54 if(PREFERENCE_ERROR_NONE != ret){
55 PRINTFUNC(DLOG_ERROR, "preference_get_int error!(%d)", ret);
58 ret = vconf_get_int(VCONFKEY_ISE_STT_LANGUAGE, &lang);
60 PRINTFUNC(DLOG_ERROR, "Vconf_get_int error!(%d)", ret);
65 if((strcmp(voicedata->kbd_lang, "zh_CN") == 0) || (strcmp(voicedata->kbd_lang, "ja_JP") == 0))
79 char * error_string(int ecode)
83 case STT_ERROR_OUT_OF_MEMORY:
84 str = "STT_ERROR_OUT_OF_MEMORY";
86 case STT_ERROR_IO_ERROR:
87 str = "STT_ERROR_IO_ERROR";
89 case STT_ERROR_INVALID_PARAMETER:
90 str = "STT_ERROR_INVALID_PARAMETER";
92 case STT_ERROR_TIMED_OUT:
93 str = "STT_ERROR_TIMED_OUT";
95 case STT_ERROR_RECORDER_BUSY:
96 str = "STT_ERROR_RECORDER_BUSY";
98 case STT_ERROR_OUT_OF_NETWORK:
99 str = "STT_ERROR_OUT_OF_NETWORK";
101 case STT_ERROR_INVALID_STATE:
102 str = " STT_ERROR_INVALID_STATE";
104 case STT_ERROR_INVALID_LANGUAGE:
105 str = "STT_ERROR_INVALID_LANGUAGE";
107 case STT_ERROR_ENGINE_NOT_FOUND:
108 str = "STT_ERROR_ENGINE_NOT_FOUND";
110 case STT_ERROR_OPERATION_FAILED:
111 str = "STT_ERROR_OPERATION_FAILED";
113 case STT_ERROR_NOT_SUPPORTED_FEATURE:
114 str = "STT_ERROR_NOT_SUPPORTED_FEATURE";
120 void voice_stt_set_silence_detection_func(bool bEnable)
122 int ret = STT_ERROR_NONE;
124 stt_option_silence_detection_e s_option;
127 s_option = STT_OPTION_SILENCE_DETECTION_TRUE;
129 s_option = STT_OPTION_SILENCE_DETECTION_FALSE;
131 ret = stt_set_silence_detection(g_stt, s_option);
132 if (STT_ERROR_NONE != ret) {
133 PRINTFUNC(DLOG_ERROR, "stt_set_silence_detection Failed : error(%d) = %s", ret, error_string((stt_error_e)ret));
135 PRINTFUNC(NO_PRINT, "stt_set_silence_detection Successful");
140 ////////////////////////////////////////////////////////////////////////////////
141 // STT Callback functions
142 ////////////////////////////////////////////////////////////////////////////////
144 void on_feedback(stt_h handle)
147 int is_sound_vibe = 0;
149 if(vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &is_sound)) {
150 PRINTFUNC(DLOG_ERROR, "get sound status failed.");
153 if(vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &is_sound_vibe)) {
154 PRINTFUNC(DLOG_ERROR, "get vibe status failed.");
157 if (is_sound || is_sound_vibe) {
158 stt_set_start_sound(handle, "/usr/share/ise-voice-input/audio/voice_start.wav");
159 stt_set_stop_sound(handle, "/usr/share/ise-voice-input/audio/voice_stop.wav");
161 stt_unset_start_sound(handle);
162 stt_unset_stop_sound(handle);
166 ////////////////////////////////////////////////////////////////////////////////
168 ////////////////////////////////////////////////////////////////////////////////
170 bool _app_stt_initialize(VoiceData *voice_data)
172 PRINTFUNC(NO_PRINT, "_app_stt_initialize");
173 VoiceData *vd = (VoiceData *)voice_data;
177 vd->sttmanager->Cancel();
178 delete vd->sttmanager;
179 vd->sttmanager = NULL;
182 if(vd->sttfeedback) {
183 delete vd->sttfeedback;
184 vd->sttfeedback = NULL;
187 vd->sttfeedback = new is::stt::SttFeedback();
188 vd->sttfeedback->SetVoiceData(vd);
190 vd->sttmanager = new is::stt::SttManager(*(vd->sttfeedback));
191 vd->sttmanager->Prepare();
192 } catch(std::exception &e) {
193 PRINTFUNC(DLOG_ERROR, "%s", e.what());