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"
44 const char * error_string(int ecode)
46 const char *str = NULL;
48 case STT_ERROR_OUT_OF_MEMORY:
49 str = "STT_ERROR_OUT_OF_MEMORY";
51 case STT_ERROR_IO_ERROR:
52 str = "STT_ERROR_IO_ERROR";
54 case STT_ERROR_INVALID_PARAMETER:
55 str = "STT_ERROR_INVALID_PARAMETER";
57 case STT_ERROR_TIMED_OUT:
58 str = "STT_ERROR_TIMED_OUT";
60 case STT_ERROR_RECORDER_BUSY:
61 str = "STT_ERROR_RECORDER_BUSY";
63 case STT_ERROR_OUT_OF_NETWORK:
64 str = "STT_ERROR_OUT_OF_NETWORK";
66 case STT_ERROR_INVALID_STATE:
67 str = " STT_ERROR_INVALID_STATE";
69 case STT_ERROR_INVALID_LANGUAGE:
70 str = "STT_ERROR_INVALID_LANGUAGE";
72 case STT_ERROR_ENGINE_NOT_FOUND:
73 str = "STT_ERROR_ENGINE_NOT_FOUND";
75 case STT_ERROR_OPERATION_FAILED:
76 str = "STT_ERROR_OPERATION_FAILED";
78 case STT_ERROR_NOT_SUPPORTED_FEATURE:
79 str = "STT_ERROR_NOT_SUPPORTED_FEATURE";
85 void voice_stt_set_silence_detection_func(bool bEnable)
87 int ret = STT_ERROR_NONE;
89 stt_option_silence_detection_e s_option;
92 s_option = STT_OPTION_SILENCE_DETECTION_TRUE;
94 s_option = STT_OPTION_SILENCE_DETECTION_FALSE;
96 ret = stt_set_silence_detection(g_stt, s_option);
97 if (STT_ERROR_NONE != ret) {
98 PRINTFUNC(DLOG_ERROR, "stt_set_silence_detection Failed : error(%d) = %s", ret, error_string((stt_error_e)ret));
100 PRINTFUNC(NO_PRINT, "stt_set_silence_detection Successful");
105 ////////////////////////////////////////////////////////////////////////////////
106 // STT Callback functions
107 ////////////////////////////////////////////////////////////////////////////////
109 void on_feedback(stt_h handle)
112 int is_sound_vibe = 0;
114 if(vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &is_sound)) {
115 PRINTFUNC(DLOG_ERROR, "get sound status failed.");
118 if(vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &is_sound_vibe)) {
119 PRINTFUNC(DLOG_ERROR, "get vibe status failed.");
122 if (is_sound || is_sound_vibe) {
123 stt_set_start_sound(handle, "/usr/share/ise-voice-input/audio/voice_start.wav");
124 stt_set_stop_sound(handle, "/usr/share/ise-voice-input/audio/voice_stop.wav");
126 stt_unset_start_sound(handle);
127 stt_unset_stop_sound(handle);
131 ////////////////////////////////////////////////////////////////////////////////
133 ////////////////////////////////////////////////////////////////////////////////
135 bool _app_stt_initialize(VoiceData *voice_data)
137 PRINTFUNC(NO_PRINT, "_app_stt_initialize");
138 VoiceData *vd = (VoiceData *)voice_data;
142 vd->sttmanager->Cancel();
143 delete vd->sttmanager;
144 vd->sttmanager = NULL;
147 if(vd->sttfeedback) {
148 delete vd->sttfeedback;
149 vd->sttfeedback = NULL;
152 vd->sttfeedback = new is::stt::SttFeedback();
153 vd->sttfeedback->SetVoiceData(vd);
155 vd->sttmanager = new is::stt::SttManager(*(vd->sttfeedback));
156 vd->sttmanager->Prepare();
157 } catch(std::exception &e) {
158 PRINTFUNC(DLOG_ERROR, "%s", e.what());