我对Watson语音文本有一些问题,当我尝试发送文件时出现超时错误。
错误如下:
以下代码:
final InputStream inputStream = FileUtils.openInputStream(files[spnRecordingList.getSelectedItemPosition()]);
final FileInputStream input2 = new FileInputStream(files[spnRecordingList.getSelectedItemPosition()]);
Log.i("transcribe", "input2 created");
recognizeOptions = new RecognizeOptions.Builder().contentType(HttpMediaType.AUDIO_WAV).maxAlternatives(3).interimResults(true).build();
Log.i("transcribe", "options");
final BaseRecognizeCallback callback = new BaseRecognizeCallback() {
@Override
public void onTranscription(SpeechResults speechResults) {
Log.i("callback", "on transcription");
txtbox.setText(speechResults.toString());
}
@Override
public void onError(Exception e){
Log.i("callback", "on error");
Log.i("callback", e.toString());
e.printStackTrace();
}
@Override
public void onDisconnected() {
Log.i("callback", "on disconnected");
}
};
new Thread(new Runnable() {
@Override
public void run() {
try {
service.recognizeUsingWebSocket(inputStream, recognizeOptions, callback);
// service.recognize(files[spnRecordingList.getSelectedItemPosition()], recognizeOptions);
Log.i("transcribe", "inside the try statement");
} catch (Exception e) {
Log.e("try", e.toString());
}
}
}).start();
}
堆栈跟踪
java.net.SocketTimeoutException: timeout
okio.Okio$4.newTimeoutException(Okio.java:230)
okio.AsyncTimeout.exit(AsyncTimeout.java:285)
okio.AsyncTimeout$2.read(AsyncTimeout.java:241)
okio.RealBufferedSource.indexOf(RealBufferedSource.java:345)
okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:217)
okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:211)
okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:189)
okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:75)
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)
okhttp3.RealCall$AsyncCall.execute(RealCall.java:135)
okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
java.lang.Thread.run(Thread.java:762)
Caused by: java.net.SocketTimeoutException: Read timed out
com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method)
com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:789)
okio.Okio$2.read(Okio.java:139)
okio.AsyncTimeout$2.read(AsyncTimeout.java:237)
... 23 more
我已经在网上查询并询问了IBM的开发社区并且无法解决为什么我会遇到问题,因为我遵循了IBM在这里提供的示例github