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.
18 #include "SttFeedback.h"
20 #include "w-input-stt-engine.h"
21 #include "w-input-stt-voice.h"
23 using namespace is::stt;
25 SttFeedback::SttFeedback()
32 SttFeedback::~SttFeedback()
39 void SttFeedback::OnResult (
41 stt_result_event_e event,
42 std::vector<std::string> results,
47 VoiceData& vd = *((VoiceData *) owner);
49 if(vd.state == STT_STATE_VAL_TERMINATING) {
50 PRINTFUNC(DLOG_WARN, "STT_STATE_VAL_TERMINATING");
55 // Partial result case : STT_RECOGNITION_TYPE_FREE_PARTIAL
56 // Normal result case : STT_RECOGNITION_TYPE_FREE
58 if(results.size() < 0) {
59 PRINTFUNC(DLOG_ERROR, "Result size : %d", results.size());
60 vd.state = STT_STATE_VAL_NOT_RECOGNISED;
61 set_animation_state(&vd);
64 PRINTFUNC(DLOG_INFO, "Meaningful result : size (%d)", results.size());
66 for(auto result : results) {
67 PRINTFUNC(DLOG_INFO, "Results");
68 if(!result.empty() && result.length() > 0) {
69 PRINTFUNC(DLOG_INFO,"%s\n", result.c_str());
71 case STT_RESULT_EVENT_FINAL_RESULT:
72 PRINTFUNC(DLOG_DEBUG,"STT_RESULT_EVENT_FINAL_RESULT");
73 vd.state = STT_STATE_VAL_INIT;
74 set_animation_state(&vd);
75 vd.result_type = STT_RESULT_EVENT_FINAL_RESULT;
76 voice_get_string(result.c_str(), &vd);
78 case STT_RESULT_EVENT_PARTIAL_RESULT:
79 PRINTFUNC(DLOG_DEBUG,"STT_RESULT_EVENT_PARTIAL_RESULT");
80 vd.result_type = STT_RESULT_EVENT_PARTIAL_RESULT;
81 voice_get_string(result.c_str(), &vd);
84 PRINTFUNC(DLOG_INFO, "");
89 PRINTFUNC(DLOG_INFO, "Empty result");
92 PRINTFUNC(DLOG_INFO, "Need to specify this case");
97 * if recognized result doesn't have any data,
98 * it will process as recognition fail.
101 //vd.state = STT_STATE_VAL_NOT_RECOGNISED;
102 vd.state = STT_STATE_VAL_INIT;
103 set_animation_state(&vd);
108 void SttFeedback::AutoStart(void) {
109 PRINTFUNC(DLOG_DEBUG, "start");
111 if (elm_config_access_get()){
112 PRINTFUNC(DLOG_DEBUG, "accessbility on: It will not start automatically.");
114 start_by_press((VoiceData *) owner);
119 void SttFeedback::SttIdle(void)
122 PRINTFUNC(DLOG_WARN, "no owner");
126 VoiceData& vd = *((VoiceData *) owner);
131 * When recognition is failed, do nothing.
132 * Because after result, it's called continuous. So it looks not natural.
134 * So in this case, we will not change as INIT state.
135 * using 2 sec timer, it will change as idle state.
138 if(vd.state == STT_STATE_VAL_NOT_RECOGNISED) {
139 PRINTFUNC(DLOG_INFO, "Ignore when state was STT_STATE_VAL_NOT_RECOGNISED");
143 PRINTFUNC(DLOG_DEBUG, "UI will go to idle state");
145 vd.state = STT_STATE_VAL_INIT;
146 set_animation_state(&vd);
151 void SttFeedback::SttRecording(void)
154 PRINTFUNC(DLOG_WARN, "no owner");
158 VoiceData& vd = *((VoiceData *) owner);
160 if(vd.partial_result){
161 free(vd.partial_result);
162 vd.partial_result = NULL;
165 PRINTFUNC(DLOG_DEBUG, "UI will go to listening state");
167 vd.state = STT_STATE_VAL_LISTENING;
168 set_animation_state(&vd);
173 void SttFeedback::SttProcessing(void)
176 PRINTFUNC(DLOG_WARN, "no owner");
180 VoiceData& vd = *((VoiceData *) owner);
182 PRINTFUNC(DLOG_DEBUG, "UI will go to processing state");
184 vd.state = STT_STATE_VAL_PROCESSING;
185 set_animation_state(&vd);
190 void SttFeedback::OnError(stt_error_e reason)
193 PRINTFUNC(DLOG_WARN, "no owner");
197 VoiceData& vd = *((VoiceData *) owner);
199 PRINTFUNC(DLOG_ERROR,"error = %d\n", reason);
200 vd.state = STT_STATE_VAL_INIT;
201 set_animation_state(&vd);
202 show_error_message(&vd, reason);
206 void SttFeedback::SetVoiceData(void *data) {
209 PRINTFUNC(DLOG_WARN, "no data");