17
17
import android .widget .Toast ;
18
18
19
19
import com .airbnb .lottie .LottieAnimationView ;
20
+ import com .example .gaid .model .get_case .GetCaseRequestDTO ;
21
+ import com .example .gaid .model .get_case .GetCaseResponseDTO ;
22
+ import com .example .gaid .util .RestApiUtil ;
20
23
21
24
import java .util .ArrayList ;
22
25
import java .util .List ;
25
28
import kr .co .shineware .nlp .komoran .core .Komoran ;
26
29
import kr .co .shineware .nlp .komoran .model .KomoranResult ;
27
30
import kr .co .shineware .nlp .komoran .model .Token ;
31
+ import retrofit2 .Call ;
32
+ import retrofit2 .Callback ;
33
+ import retrofit2 .Response ;
28
34
29
35
30
36
public class SoundActivity extends Activity implements TextToSpeech .OnInitListener {
@@ -36,6 +42,9 @@ public class SoundActivity extends Activity implements TextToSpeech.OnInitListen
36
42
Intent intent ;
37
43
SpeechRecognizer mRecognizer ;
38
44
45
+ private RestApiUtil mRestApiUtil ;
46
+ private GetCaseRequestDTO mGetCaseRequestDTO ;
47
+ private GetCaseResponseDTO mGetCaseResponseDTO ;
39
48
private String mCase ;
40
49
//Komoran 형태소 분석기
41
50
private Komoran mKomoran ;
@@ -81,8 +90,12 @@ public void init()
81
90
intent .putExtra (RecognizerIntent .EXTRA_LANGUAGE ,"ko-KR" );
82
91
mRecognizer = SpeechRecognizer .createSpeechRecognizer (this );
83
92
mRecognizer .setRecognitionListener (listener );
93
+
94
+ mGetCaseRequestDTO = new GetCaseRequestDTO ();
95
+ mRestApiUtil = new RestApiUtil ();
84
96
}
85
- private void speakOut (String text ) {
97
+
98
+ public void speakOut (String text ) {
86
99
textToSpeech .speak (text , TextToSpeech .QUEUE_FLUSH , null );
87
100
boolean speakingEnd = textToSpeech .isSpeaking ();
88
101
Log .d ("TTS" , "SPOKE" );
@@ -162,64 +175,39 @@ public void onError(int error) {
162
175
public void onResults (Bundle results ) {
163
176
// 말을 하면 ArrayList에 단어를 넣고 textView에 단어를 이어줍니다.
164
177
165
- mKomoran = new Komoran ("models_full" );
166
- mKomoran .setFWDic ("user_data/fwd.user" );
167
- mKomoran .setUserDic ("user_data/dic.user" );
168
-
169
178
String text = "" ;
170
179
ArrayList <String > matches =
171
180
results .getStringArrayList (SpeechRecognizer .RESULTS_RECOGNITION );
172
181
animationView .cancelAnimation ();
173
182
174
- // for(int i = 0; i < matches.size() ; i++){
175
- // sttResultTextView.setText(matches.get(i));
176
- // }
183
+ for (int i = 0 ; i < matches .size () ; i ++){
184
+ sttResultTextView .setText (matches .get (i ));
185
+ }
177
186
178
- sttResultTextView .setText (matches .get (0 ));
179
187
text = sttResultTextView .getText ().toString ();
180
188
181
- KomoranResult analyzeResultList = mKomoran .analyze (text );
182
- //List<Token> tokenList = analyzeResultList.getTokenList();
183
- mCase = checkCase (analyzeResultList .getMorphesByTags ("VV" , "NP" , "NNG" , "SN" )); //NNB
189
+ mGetCaseRequestDTO .setMorph (text );
190
+ mCase = getCase (mGetCaseRequestDTO );
184
191
185
-
186
- if (mCase .contains ("MapActivity" )) {
192
+ if (mCase .contains ("MapActivity" )) { //길 찾기
187
193
speakOut ("길찾기기능을 찾으셨군요" );
188
194
Intent intent = new Intent (getApplicationContext (), MapActivity .class );
189
195
startActivity (intent );
190
- <<<<<<< HEAD
191
196
}
192
- else if (text .contains ("소개" )) {
193
- speakOut ("소개 해달라구요?" );
194
-
195
- }
196
- else if (mCase .contains ("TakepictureActivity" )) {
197
- =======
198
- } else if (text .contains ("소개" )||text .contains ("소계" )||text .contains ("속의" )) {
199
- speakOut ("소개 해달라구요?" );
200
- Intent intent = new Intent (getApplicationContext (), InfoActivity .class );
201
- startActivity (intent );
202
-
203
- } else if (text .contains ("사진" )) {
204
- >>>>>>> c2fbbb25dea3c83ee7c67cbef7574f326c204077
197
+ else if (mCase .contains ("TakepictureActivity" )) { //기념 사진
205
198
speakOut ("기념사진찍어드릴게요" );
206
199
Intent intent = new Intent (getApplicationContext (), TakepictureActivity .class );
207
200
startActivity (intent );
208
201
}
209
- else if (text .contains ("대양" )) {
210
- speakOut ("대양이를 불르셨어요?" );
211
- Intent intent = new Intent (getApplicationContext (), SoundActivity .class );
202
+ else if (mCase .contains ("InfoActivity" )) {
203
+ speakOut ("소개 해달라구요?" );
204
+ Intent intent = new Intent (getApplicationContext (), InfoActivity .class );
205
+ intent .putExtra ("roomNo" , mGetCaseResponseDTO .getRoomNo ());
212
206
startActivity (intent );
213
- <<<<<<< HEAD
214
- =======
215
- } else {
216
- speakOut ("다시 한번 말해주세요" );
217
- mRecognizer .startListening (intent );
218
-
219
- >>>>>>> c2fbbb25dea3c83ee7c67cbef7574f326c204077
220
207
}
221
208
else {
222
- speakOut ("다시 한번 말해주세요." );
209
+ speakOut ("다시 한번 말해주세요" );
210
+ mRecognizer .startListening (intent );
223
211
}
224
212
225
213
// if (text.contains("길")||text.contains("어떻게 가")||text.contains("어디에 있어")) {
@@ -274,30 +262,49 @@ public void onInit(int status) {
274
262
}
275
263
}
276
264
277
- public String checkCase (List < String > analyzeResultList ) {
265
+ public String checkCase () {
278
266
String checkCase = null ;
279
- if (analyzeResultList .contains ("가" )) { //길 찾기
280
- checkCase = "MapActivity" ;
281
- } else if (analyzeResultList .contains ("찾" )) { //길 찾기
282
- checkCase = "MapActivity" ;
283
- } else if (analyzeResultList .contains ("찍" )) { //기념사진
284
- checkCase = "TakepictureActivity" ;
285
- }
286
267
287
- if (analyzeResultList . contains ("어디 " )) { //길 찾기
268
+ if (mGetCaseResponseDTO . getFunction (). contains ("navi " )) { //길 찾기 //MapActivity
288
269
checkCase = "MapActivity" ;
289
270
}
290
-
291
- if (analyzeResultList .contains ("길" )) { //길 찾기
292
- checkCase = "MapActivity" ;
293
- } else if (analyzeResultList .contains ("소개" )) { //안내
294
-
295
- } else if (analyzeResultList .contains ("사진" )) { // 기념사진
296
- checkCase = "TakepictureActivity" ;
297
- } else if (analyzeResultList .contains ("촬영" )) { //기념사진
271
+ else if (mGetCaseResponseDTO .getFunction ().contains ("info" )) { //안내 //InfoActivity
272
+ checkCase = "InfoActivity" ;
273
+ }
274
+ else if (mGetCaseResponseDTO .getFunction ().contains ("cam" )) { //기념사진 //TakepictureActivity
298
275
checkCase = "TakepictureActivity" ;
299
276
}
277
+ //else if (mGetCaseResponseDTO) { //길찾기인가 안내인가 // navi_info
278
+ // checkCase = "PopUpActivity";
279
+ //}
300
280
301
281
return checkCase ;
302
282
}
283
+
284
+ public String getCase (GetCaseRequestDTO mGetCaseRequestDTO ) {
285
+ String activityCase = "" ;
286
+ mRestApiUtil .getApi ().get_case (mGetCaseRequestDTO ).enqueue (new Callback <GetCaseResponseDTO >() {
287
+ @ Override
288
+ public void onResponse (Call <GetCaseResponseDTO > call , Response <GetCaseResponseDTO > response ) {
289
+ if (response .isSuccessful ()) {
290
+ mGetCaseResponseDTO = response .body ();
291
+ checkCase ();
292
+ }
293
+ else {
294
+ System .out .println ("onResponse 에서 에러남. not response.isSuccessful" );
295
+ speakOut ("정확하게 다시 한번 말해주세요" );
296
+ mRecognizer .startListening (intent );
297
+ }
298
+ }
299
+
300
+ @ Override
301
+ public void onFailure (Call <GetCaseResponseDTO > call , Throwable t ) {
302
+ System .out .println ("onFailure, t.getMessage : " + t .getMessage ());
303
+ speakOut ("정확하게 다시 한번 말해주세요" );
304
+ mRecognizer .startListening (intent );
305
+ }
306
+ });
307
+
308
+ return activityCase ;
309
+ }
303
310
}
0 commit comments