Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.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
Java 谷歌云演讲没有回应_Java_Google Cloud Platform_Google Cloud Speech - Fatal编程技术网

Java 谷歌云演讲没有回应

Java 谷歌云演讲没有回应,java,google-cloud-platform,google-cloud-speech,Java,Google Cloud Platform,Google Cloud Speech,我正在尝试使用谷歌云语音api。我发现一种奇怪的行为发生了好几次。我不明白为什么,我无法从谷歌云演讲中得到任何回应 代码如下: public String ConvertSpeech(File audioFile) { SpeechClient speech = null; try { speech = SpeechClient.create(); } catch (IOException e) { e.printStackTrace

我正在尝试使用谷歌云语音api。我发现一种奇怪的行为发生了好几次。我不明白为什么,我无法从谷歌云演讲中得到任何回应

代码如下:

 public String ConvertSpeech(File audioFile) {
      SpeechClient speech = null;
    try {
        speech = SpeechClient.create();
    } catch (IOException e) {
        e.printStackTrace();
    }
      Path path = Paths.get(audioFile.getName());
      byte[] data = null;
    try {
        data = Files.readAllBytes(path);
    } catch (IOException e) {
        e.printStackTrace();
    }
      ByteString audioBytes = ByteString.copyFrom(data);
      // Configure request with local raw PCM audio
      RecognitionConfig config = RecognitionConfig.newBuilder()
          .setEncoding(AudioEncoding.LINEAR16)
          .setLanguageCode("fr-FR")
          .setSampleRateHertz(16000)
          .build();
      RecognitionAudio audio = RecognitionAudio.newBuilder()
          .setContent(audioBytes)
          .build();
      // Use blocking call to get audio transcript
    //  RecognizeResponse response = speech.recognize(config, audio);
        OperationFuture<LongRunningRecognizeResponse, LongRunningRecognizeMetadata> response =
                speech.longRunningRecognizeAsync(config, audio);

        while (!response.isDone()) {
            System.out.println("Waiting for response...");
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
          }
        List<SpeechRecognitionResult> results = new ArrayList<>();
        try {
            results = response.get().getResultsList();
        } catch (InterruptedException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (ExecutionException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    //  List<SpeechRecognitionResult> results = response.getResultsList();
        // There can be several alternative transcripts for a given chunk of speech. Just use the
        // first (most likely) one here.
      if(results.size()!=0){
          SpeechRecognitionAlternative alternative = results.get(0).getAlternativesList().get(0);
           // System.out.printf("Transcription: %s%n", alternative.getTranscript());
            try {
                speech.close();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return alternative.getTranscript(); 
      }
       // System.out.printf("Transcription: %s%n", alternative.getTranscript());
        try {
            speech.close();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "";

    }
OperationFuture<LongRunningRecognizeResponse, LongRunningRecognizeMetadata> 
    response = speech.longRunningRecognizeAsync(config, audio);
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
Waiting for response...
java.util.concurrent.ExecutionException: com.google.api.gax.rpc.DeadlineExceededException: io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED: deadline exceeded after 599979147331ns
at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:500)
at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:459)
at com.google.api.gax.longrunning.OperationFutureImpl.get(OperationFutureImpl.java:106)
at mypackage.GoogleCloudSpeechService.ConvertSpeech(GoogleCloudSpeechService.java:66)