首页 > 解决方案 > 在 Google SpeechClient 上会引发 NoSuchMethodError 识别()

问题描述

我正在使用 Google Speech-To-Text 客户端库将一些 .wav 文件转换为文本。我已阅读文档并使用示例代码尝试它是否首先有效。但是,我遇到了如下 NoSuchMethodError 方法。

public void Transcribe(String serviceAccountKeyPath) throws Exception {
    CredentialsProvider credentialProvider = FixedCredentialsProvider.create(ServiceAccountCredentials.fromStream(new FileInputStream(serviceAccountKeyPath)));
    SpeechSettings settings = SpeechSettings.newBuilder().setCredentialsProvider(credentialProvider).build();

    try (SpeechClient speechClient = SpeechClient.create(settings)) {
        RecognitionConfig config = RecognitionConfig.newBuilder()
                .setEncoding(AudioEncoding.FLAC)
                .setLanguageCode("en-US")
                .setSampleRateHertz(16000)
                .build();

        RecognitionAudio audio = RecognitionAudio.newBuilder().setUri("gs://xxx").build();

        RecognizeResponse res = speechClient.recognize(config, audio);
        List<SpeechRecognitionResult> results = res.getResultsList();

        for (SpeechRecognitionResult result : results) {
            SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0);
            System.out.printf("TRANSCRIPTION: %s%n", alternative.getTranscript());
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}

以下是执行识别()时的错误跟踪:

com.google.common.util.concurrent.ExecutionError: java.lang.NoSuchMethodError: io.opencensus.tags.TagContextBuilder.putPropagating(Lio/opencensus/tags/TagKey;Lio/opencensus/tags/TagValue;)Lio/opencensus/tags/TagContextBuilder;
    at com.google.common.util.concurrent.Futures.wrapAndThrowUnchecked(Futures.java:1250)
    at com.google.common.util.concurrent.Futures.getUnchecked(Futures.java:1243)
    at com.google.api.gax.rpc.ApiExceptions.callAndTranslateApiException(ApiExceptions.java:53)
    at com.google.api.gax.rpc.UnaryCallable.call(UnaryCallable.java:112)
    at com.google.cloud.speech.v1.SpeechClient.recognize(SpeechClient.java:244)
    at com.google.cloud.speech.v1.SpeechClient.recognize(SpeechClient.java:208)

标签: javaeclipsegoogle-cloud-speech

解决方案


推荐阅读