if(left_sound < right_sound) {
System.out.println("111");
// 오른쪽
String TAG = this.getClass().getSimpleName();
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
HttpURLConnection conn = null;
try {
URL url = new URL("https://kakaoi-newtone-openapi.kakao.com/v1/recognize");
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Transfer-Encoding", "chunked"); // 파일 전송
conn.setRequestProperty("Content-Type", "application/octet-stream");
conn.setRequestProperty("X-DSS-Service", "DICTATION");
conn.setRequestProperty("Authorization", "KakaoAK {a1595e796b8ab30ce6b2993836b8ec6f}");
conn.setDoOutput(true);
File wavfile_R = new File(fn1);
if (wavfile_R.exists()) {
Log.d(TAG, "있다");
} else {
Log.d(TAG, "없다");
}
byte[] bytes = Files.readAllBytes(wavfile_R.toPath());
Log.d(TAG, "길이==" + bytes.length);
DataOutputStream request = new DataOutputStream(conn.getOutputStream()); // 오른쪽
request.write(bytes);
request.flush();
request.close();
StringBuilder sb = new StringBuilder();
if (conn.getResponseCode() == HttpsURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
String line;
while ((line = in.readLine()) != null) {
sb.append(line).append("\n");
}
in.close();
System.out.println("" + sb.toString());
result = sb.toString();
conn.disconnect();
} else {
Log.d(TAG, "여기");
System.out.println(conn.getResponseMessage());
result = conn.getResponseCode() + conn.getResponseMessage();
System.out.println(result);
}
} catch (Exception e) {
Log.d(TAG, "저기");
System.out.println(e.toString());
}
} else {
System.out.println("222");
// 왼쪽
String TAG1 = this.getClass().getSimpleName();
StrictMode.ThreadPolicy policy1 = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy1);
HttpURLConnection conn1 = null;
try {
URL url = new URL("https://kakaoi-newtone-openapi.kakao.com/v1/recognize");
conn1 = (HttpURLConnection) url.openConnection();
conn1.setRequestMethod("POST");
conn1.setRequestProperty("Transfer-Encoding", "chunked"); // 파일 전송
conn1.setRequestProperty("Content-Type", "application/octet-stream");
conn1.setRequestProperty("X-DSS-Service", "DICTATION");
conn1.setRequestProperty("Authorization", "KakaoAK {a1595e796b8ab30ce6b2993836b8ec6f}");
conn1.setDoOutput(true);
File wavfile_L = new File(fn);
if (wavfile_L.exists()) {
Log.d(TAG1, "있다");
} else {
Log.d(TAG1, "없다");
}
byte[] bytes1 = Files.readAllBytes(wavfile_L.toPath());
Log.d(TAG1, "길이==" + bytes1.length);
DataOutputStream request = new DataOutputStream(conn1.getOutputStream()); // 오른쪽
request.write(bytes1);
request.flush();
request.close();
StringBuilder sb1 = new StringBuilder();
if (conn1.getResponseCode() == HttpsURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(conn1.getInputStream(), "UTF-8"));
String line;
while ((line = in.readLine()) != null) {
sb1.append(line).append("\n");
}
in.close();
System.out.println("" + sb1.toString());
result = sb1.toString();
conn1.disconnect();
} else {
Log.d(TAG1, "여기");
System.out.println(conn1.getResponseMessage());
result = conn1.getResponseCode() + conn1.getResponseMessage();
System.out.println(result);
}
} catch (Exception e) {
Log.d(TAG1, "저기");
System.out.println(e.toString());
}
}
result 가 401Unauthorized가 뜨네요 api 호출 부분에서는 문제가 없는데 왜 이렇게 뜨는거죠 ??