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()
30 SttFeedback::~SttFeedback()
34 void SttFeedback::OnResult(
36 stt_result_event_e event,
37 std::vector<std::string> results,
41 VoiceData& vd = *((VoiceData *) owner);
43 if (vd.state == STT_STATE_VAL_TERMINATING) {
44 PRINTFUNC(DLOG_WARN, "STT_STATE_VAL_TERMINATING");
49 // Partial result case : STT_RECOGNITION_TYPE_FREE_PARTIAL
50 // Normal result case : STT_RECOGNITION_TYPE_FREE
52 if(results.size() < 1) {
53 PRINTFUNC(DLOG_ERROR, "Result size : %d", results.size());
54 vd.state = STT_STATE_VAL_NOT_RECOGNISED;
55 set_animation_state(&vd);
57 PRINTFUNC(DLOG_INFO, "Meaningful result : size (%d)", results.size());
59 for(auto result : results) {
60 PRINTFUNC(DLOG_INFO, "Results");
61 if(!result.empty() && result.length() > 0) {
62 PRINTFUNC(DLOG_INFO, "%s\n", result.c_str());
64 case STT_RESULT_EVENT_FINAL_RESULT:
65 PRINTFUNC(DLOG_DEBUG, "STT_RESULT_EVENT_FINAL_RESULT");
66 vd.state = STT_STATE_VAL_INIT;
67 set_animation_state(&vd);
68 vd.result_type = STT_RESULT_EVENT_FINAL_RESULT;
69 voice_get_string(result.c_str(), &vd);
71 case STT_RESULT_EVENT_PARTIAL_RESULT:
72 PRINTFUNC(DLOG_DEBUG, "STT_RESULT_EVENT_PARTIAL_RESULT");
73 vd.result_type = STT_RESULT_EVENT_PARTIAL_RESULT;
74 voice_get_string(result.c_str(), &vd);
76 case STT_RESULT_EVENT_ERROR:
77 PRINTFUNC(DLOG_DEBUG, "STT_RESULT_EVENT_ERROR");
78 vd.state = STT_STATE_VAL_NOT_RECOGNISED;
79 set_animation_state(&vd);
82 PRINTFUNC(DLOG_INFO, "");
87 PRINTFUNC(DLOG_INFO, "Empty result");
90 PRINTFUNC(DLOG_INFO, "Need to specify this case");
95 * if recognized result doesn't have any data,
96 * it will process as recognition fail.
99 //vd.state = STT_STATE_VAL_NOT_RECOGNISED;
100 vd.state = STT_STATE_VAL_INIT;
101 set_animation_state(&vd);
105 void SttFeedback::AutoStart(void) {
106 PRINTFUNC(DLOG_DEBUG, "start");
107 start_by_press((VoiceData *) owner);
110 void SttFeedback::SttIdle(void)
113 PRINTFUNC(DLOG_WARN, "no owner");
117 VoiceData& vd = *((VoiceData *) owner);
122 * When recognition is failed, do nothing.
123 * Because after result, it's called continuous. So it looks not natural.
125 * So in this case, we will not change as INIT state.
126 * using 2 sec timer, it will change as idle state.
129 if (vd.state == STT_STATE_VAL_NOT_RECOGNISED) {
130 PRINTFUNC(DLOG_INFO, "Ignore when state was STT_STATE_VAL_NOT_RECOGNISED");
134 PRINTFUNC(DLOG_DEBUG, "UI will go to idle state");
136 vd.state = STT_STATE_VAL_INIT;
137 set_animation_state(&vd);
140 void SttFeedback::SttRecording(void)
143 PRINTFUNC(DLOG_WARN, "no owner");
147 VoiceData& vd = *((VoiceData *) owner);
149 if(vd.partial_result){
150 free(vd.partial_result);
151 vd.partial_result = NULL;
154 PRINTFUNC(DLOG_DEBUG, "UI will go to listening state");
156 vd.state = STT_STATE_VAL_LISTENING;
157 set_animation_state(&vd);
160 void SttFeedback::SttProcessing(void)
163 PRINTFUNC(DLOG_WARN, "no owner");
167 VoiceData& vd = *((VoiceData *) owner);
169 PRINTFUNC(DLOG_DEBUG, "UI will go to processing state");
171 vd.state = STT_STATE_VAL_PROCESSING;
172 set_animation_state(&vd);
177 void SttFeedback::OnError(stt_error_e reason)
180 PRINTFUNC(DLOG_WARN, "no owner");
184 VoiceData& vd = *((VoiceData *) owner);
186 PRINTFUNC(DLOG_ERROR, "error = %d\n", reason);
187 vd.state = STT_STATE_VAL_INIT;
188 set_animation_state(&vd);
189 show_error_message(&vd, reason);
193 void SttFeedback::SetVoiceData(void *data) {
195 PRINTFUNC(DLOG_WARN, "no data");