java - 在 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)
解决方案
推荐阅读
- javascript - 路由器在 NavigationStart 事件中导航
- python - -m 选项在 python 中代表什么?
- java - Java RestfulService 不返回 JSONArray
- eclipse - 在 Eclipse 中为 GWT 文本编辑器更改文本字体
- arrays - *ngFor - 在同一级别循环两个数组
- php - Wordpress 使用 AJAX 发布数组数据
- git - Git 流程和持续集成/持续交付
- azure - 从 Azure Blob 存储下载文件 - 错误:不支持给定路径的格式
- ffmpeg - 来自 ffmpeg 的 H264/MP4 直播流在浏览器中不起作用
- node.js - 企业防火墙/代理后面的 Firestore/gRPC