1
私は、オーディオを送信するためにUrlConnectionを使用しようとしています(Google Cloud Speech APIが要求するベース64バイト配列として表されています)。私はubuntuでRaspberry Piでこれをやっています。私のラップトップで(ubuntuでも)使用すれば、接続はうまくいきます。私はURLConnectionでjavaを使用しています。クラッシュはOutputStream out = urlConnection.getOutputStream();で発生します。urlconnection javax.net.ssl.SSLException:java.lang.IllegalStateException
Javaコード:
// URL to google + parameter with the API key.
URL googleUrl = new URL(GOOGLE_RECOGNIZER_URL + "?key=" + APIKEY);
// Open New URL connection channel.
URLConnection urlConnection;
urlConnection = googleUrl.openConnection();
// we want to do output. (input is automaticly set on true).
urlConnection.setDoOutput(true);
// No caching.
urlConnection.setUseCaches(false);
// Add headers.
urlConnection.setRequestProperty("Content-Type", "application/json");
// For sending the recorded data to google it needs to be first
// converted to a byte array.
byte[] array1 = AudioToByteArray.readAudioFileData(file);
// And next convert the byte array to a base64 string.
String audioString = Base64.getEncoder().encodeToString(array1);
// Make (JSON) Strings for configuration and location of audio file.
String testConfig = "\"config\": { \"encoding\":\"LINEAR16\", \"sampleRate\": 16000, \"languageCode\": \"nl-NL\"}";
String testAudioLoc = "\"audio\": { \"content\": \"" + audioString + "\" }";
String together = "{ " + testConfig + "," + testAudioLoc + " }";
// Send the string to google.
OutputStream out = urlConnection.getOutputStream();
OutputStreamWriter wr = new OutputStreamWriter(out);
wr.write(together);
wr.flush();
wr.close();
out.close();
エラー:
javax.net.ssl.SSLException: java.lang.IllegalStateException
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1906)
at sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1889)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1410)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1316)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1291)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
at main.ContactGoogleCloudSpeechAPI.writeOut(ContactGoogleCloudSpeechAPI.java:98)
at main.ContactGoogleCloudSpeechAPI.contactGoogleUrlCon(ContactGoogleCloudSpeechAPI.java:41)
at main.SpeechRecognition.contactAPI(SpeechRecognition.java:184)
at main.SpeechRecognition.mainLoop(SpeechRecognition.java:104)
at main.SpeechRecognition.run(SpeechRecognition.java:81)
at main.SpeechRecognition.main(SpeechRecognition.java:62)
http://stackoverflow.com/questions/37167189/illegalstateexception-thrown-by-maven-ssl-related-when-downloading-project-deは私のためにそれを解きます –