Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google语音到文本api v1:javax.net.ssl.ssLexException:断管_Java_Android_Ssl - Fatal编程技术网

Google语音到文本api v1:javax.net.ssl.ssLexException:断管

Google语音到文本api v1:javax.net.ssl.ssLexException:断管,java,android,ssl,Java,Android,Ssl,我正在使用谷歌语音转换文本来记录通话,并将其发送到谷歌服务器,将flac音频文件转换为文本。在安卓5.0和之前的版本中,一切都运行良好,但是从5.02和更高版本中,我得到了以下错误 javax.net.ssl.SSLException: Write error: ssl=0x8f548: I/O error during system call, Broken pipe 我正在使用谷歌语音api v1。有人能告诉我为什么我会得到这个吗 这是引发异常的方法 private Scanner ope

我正在使用谷歌语音转换文本来记录通话,并将其发送到谷歌服务器,将flac音频文件转换为文本。在安卓5.0和之前的版本中,一切都运行良好,但是从5.02和更高版本中,我得到了以下错误

javax.net.ssl.SSLException: Write error: ssl=0x8f548: I/O error during system call, Broken pipe
我正在使用谷歌语音api v1。有人能告诉我为什么我会得到这个吗

这是引发异常的方法

private Scanner openHttpsPostConnection(String urlStr, byte[] data) {
    InputStream in = null;
    byte[] mextrad = data;
    int resCode = -1;
    OutputStream out = null;
    // int http_status;
    try {
        URL url = new URL(urlStr);
        URLConnection urlConn = url.openConnection();

        if (!(urlConn instanceof HttpsURLConnection)) {
            throw new IOException("URL is not an Https URL");
        }

        HttpsURLConnection httpConn = (HttpsURLConnection) urlConn;
        httpConn.setAllowUserInteraction(false);
        httpConn.setInstanceFollowRedirects(true);

        httpConn.setRequestMethod("POST");
        //httpConn.setReadTimeout(15*1000);
        httpConn.setDoOutput(true);
        httpConn.setChunkedStreamingMode(0);
        httpConn.setRequestProperty("Content-Type", "audio/x-flac; rate=1600");
                //+ sampleRate);
        httpConn.setRequestProperty("AcceptEncoding", "gzip,deflate,sdch");
        httpConn.connect();

        try {
            // this opens a connection, then sends POST & headers.
            out = httpConn.getOutputStream();
            // Note : if the audio is more than 15 seconds
            // dont write it to UrlConnInputStream all in one block as this
            // sample does.
            // Rather, segment the byteArray and on intermittently, sleeping
            // thread
            // supply bytes to the urlConn Stream at a rate that approaches
            // the bitrate ( =30K per sec. in this instance ).
            Log.d("ParseStarter", "IO beg on data");
            out.write(mextrad); // one big block supplied instantly to the
                                // underlying chunker wont work for duration
                                // > 15 s.
            Log.d("ParseStarter", "IO fin on data");
            // do you need the trailer?
            // NOW you can look at the status.
            resCode = httpConn.getResponseCode();

            Log.d("ParseStarter", "POST OK resp: " +resCode+" "
                    + httpConn.getResponseMessage().getBytes().toString());

            if (resCode / 100 != 2) {
                Log.d("ParseStarter", "POST bad io ");
            }

        } catch (IOException e) {
            Log.d("ParseStarter", "FATAL " + e);

        }

        if (resCode == HttpsURLConnection.HTTP_OK) {
            Log.d("ParseStarter", "OK RESP to POST return scanner ");
            return new Scanner(httpConn.getInputStream());
        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

OutputStream自身无法在服务器上写入。您需要创建一个BufferedWriter,在获得OutputStream后在服务器上写入

.
.
.
try {
// this opens a connection, then sends POST & headers.
out = httpConn.getOutputStream();
// Note : if the audio is more than 15 seconds
// dont write it to UrlConnInputStream all in one block as this
// sample does.
// Rather, segment the byteArray and on intermittently, sleeping
// thread
// supply bytes to the urlConn Stream at a rate that approaches
// the bitrate ( =30K per sec. in this instance ).
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
writer.write(mextrad);
.
.
.
对不起,我忘了检查你的数据类型。在这种情况下,您能否尝试更改:

BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
writer.write(mextrad);


我以前从未在Android上尝试过,但我希望它会有所帮助。

我们能看到出现错误的代码吗?我已经添加了代码,请查看BufferedWriter无法写入字节数组它仍然不工作。你可能没有发现我的问题,我的应用程序在android 5.0(lolipop)中运行得很好,但问题在该版本之后开始出现。
DataOutputStream stream = new DataOutputStream(out);
stream.writeBytes(mextrad);