Google Speech API - 无响应且DEADLINE_EXCEEDED

时间:2018-01-24 21:23:30

标签: google-cloud-platform speech-to-text google-speech-api google-cloud-speech google-api-explorer

我使用以下java代码来调用Google Cloud语音API,但我没有得到任何回复,有时甚至是DEADLINE_EXCEEDED消息

注意:这适用于家庭wi-fi,仅在公司网络中我看到此问题。任何指针都非常感激

如果我错过了什么,请告诉我。此外,对于身份验证部分,我如何验证它是否经过身份验证?

   FileInputStream credentialsStream = new FileInputStream("C:/service-account-file.json");
    GoogleCredentials credentials = GoogleCredentials.fromStream(credentialsStream);
    FixedCredentialsProvider credentialsProvider = FixedCredentialsProvider.create(credentials);

    SpeechSettings speechSettings = 
            SpeechSettings.newBuilder()
                .setCredentialsProvider(credentialsProvider)
                .build();       


    // Instantiates a client

    SpeechClient speechClient = SpeechClient.create(speechSettings);    


        RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.FLAC;
            int sampleRateHertz = 16000;
            String languageCode = "en-US";
            RecognitionConfig config = RecognitionConfig.newBuilder()
              .setEncoding(encoding)
              .setSampleRateHertz(sampleRateHertz)
              .setLanguageCode(languageCode)
              .build();

             String fileName = "C:\\Hello.flac";

             Path path = Paths.get(fileName);
              byte[] data = Files.readAllBytes(path);
              ByteString audioBytes = ByteString.copyFrom(data);

              RecognitionAudio audio = RecognitionAudio.newBuilder()
                .setContent(audioBytes)
                .build();


             RecognizeResponse response = speechClient.recognize(config, audio);


            List<SpeechRecognitionResult> results = response.getResultsList();

            for (SpeechRecognitionResult result: results) {
              // There can be several alternative transcripts for a given chunk of speech. Just use the
              // first (most likely) one here.
              SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0);
              System.out.printf("Transcription: %s%n", alternative.getTranscript());
            }
            speechClient.close();
    }catch(Exception e){
        e.printStackTrace();
    }

错误StackTrace: -

com.google.api.gax.rpc.DeadlineExceededException: io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED
    at com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:51)
    at com.google.api.gax.grpc.GrpcExceptionCallable$ExceptionTransformingFuture.setException(GrpcExceptionCallable.java:118)
    at com.google.api.gax.grpc.GrpcExceptionCallable$ExceptionTransformingFuture.onFailure(GrpcExceptionCallable.java:101)
    at com.google.api.core.ApiFutures$1.onFailure(ApiFutures.java:53)
    at com.google.common.util.concurrent.Futures$4.run(Futures.java:1126)
    at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
    at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:902)
    at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:813)
    at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:677)
    at io.grpc.stub.ClientCalls$GrpcFuture.setException(ClientCalls.java:463)
    at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:439)
    at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:428)
    at io.grpc.internal.ClientCallImpl.access$100(ClientCallImpl.java:76)
    at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:514)
    at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$700(ClientCallImpl.java:431)
    at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:546)
    at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:52)
    at io.grpc.internal.SerializingExecutor$TaskRunner.run(SerializingExecutor.java:152)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:522)
    at java.util.concurrent.FutureTask.run(FutureTask.java:277)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:191)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1153)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.lang.Thread.run(Thread.java:785)
Caused by: io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED
    at io.grpc.Status.asRuntimeException(Status.java:540)
    ... 15 more

0 个答案:

没有答案