回答編集履歴
3
追追記
test
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
|
23
23
|
・音声データはバイナリを直接書き込み
|
24
24
|
|
25
|
-
|
25
|
+
(他にしれっと治ってるところがあるかもしれないです。)
|
26
26
|
|
27
27
|
```Java
|
28
28
|
|
2
修正
test
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
API弄って処理が通ったっぽいコードを置いておきます。
|
16
16
|
|
17
|
-
|
17
|
+
変更箇所としては3つ、
|
18
18
|
|
19
19
|
・multipartの記述は、multipartの仕様に沿った形に修正("<" ">"を削除)
|
20
20
|
|
1
追記
test
CHANGED
@@ -1,3 +1,89 @@
|
|
1
|
-
|
1
|
+
"<"">"こいつら含めたらいけないとか・・・?
|
2
|
+
|
3
|
+
|
2
4
|
|
3
5
|
[境界区切子](https://wiki.suikawiki.org/n/%E5%A2%83%E7%95%8C%E5%8C%BA%E5%88%87%E5%AD%90#anchor-31)
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
追記
|
10
|
+
|
11
|
+
含めたらいけなかったです。
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
API弄って処理が通ったっぽいコードを置いておきます。
|
16
|
+
|
17
|
+
改善点としては3つ、
|
18
|
+
|
19
|
+
・multipartの記述は、multipartの仕様に沿った形に修正("<" ">"を削除)
|
20
|
+
|
21
|
+
・一番最初のContent-Typeの設定をsetRequestPropertyで行うように
|
22
|
+
|
23
|
+
・音声データはバイナリを直接書き込み
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
```Java
|
28
|
+
|
29
|
+
URL url = new URL("https://api.apigw.smt.docomo.ne.jp/amiVoice/v1/recognize?APIKEY=XXXXXXXXXXXXXXXXX");
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
|
34
|
+
|
35
|
+
con.setDoOutput(true);
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
OutputStream outputStream = con.getOutputStream();
|
44
|
+
|
45
|
+
outputStream.write(("--" + boundary + "\r\n").getBytes(charset));
|
46
|
+
|
47
|
+
outputStream.write(("Content-Disposition: form-data; name=\"v\"\r\n").getBytes(charset));
|
48
|
+
|
49
|
+
outputStream.write(("\r\n").getBytes(charset));
|
50
|
+
|
51
|
+
outputStream.write(("on").getBytes(charset));
|
52
|
+
|
53
|
+
outputStream.write(("\r\n--" + boundary + "\r\n").getBytes(charset));
|
54
|
+
|
55
|
+
outputStream.write(("Content-Disposition: form-data; name=\"a\"; filename=\"audio_sample_amivoice.raw\"\r\n").getBytes(charset));
|
56
|
+
|
57
|
+
outputStream.write(("Content-Type: application/octet-stream\r\n").getBytes(charset));
|
58
|
+
|
59
|
+
outputStream.write(("\r\n").getBytes(charset));
|
60
|
+
|
61
|
+
outputStream.write(Files.readAllBytes(p));
|
62
|
+
|
63
|
+
outputStream.write(("\r\n--" + boundary + "--\r\n").getBytes(charset));
|
64
|
+
|
65
|
+
outputStream.flush();
|
66
|
+
|
67
|
+
outputStream.close();
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
//受信
|
72
|
+
|
73
|
+
InputStream stream = con.getInputStream();
|
74
|
+
|
75
|
+
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
|
76
|
+
|
77
|
+
String responseData = null;
|
78
|
+
|
79
|
+
while ((responseData = reader.readLine()) != null) {
|
80
|
+
|
81
|
+
System.out.println(responseData);
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
stream.close();
|
88
|
+
|
89
|
+
```
|