我想在android中使用凭据实例化SpeechClient对象。稍后将其用于将音频输入转换为文本。
我的代码如下:
val speechSettings = SpeechSettings.newBuilder()
.setCredentialsProvider(
FixedCredentialsProvider.create(
GoogleCredentials.fromStream(
context.resources.openRawResource(R.raw.my_key_name)
)
)
)
.build()
val speechClient = SpeechClient.create(speechSettings)
在gradle中,我添加了以下内容:
implementation 'com.google.cloud:google-cloud-speech:0.80.0-beta'
implementation "io.grpc:grpc-okhttp:1.4.0"
运行应用程序时出现以下错误:
java.lang.AbstractMethodError: abstract method "java.util.concurrent.ScheduledExecutorService io.grpc.internal.ClientTransportFactory.getScheduledExecutorService()"
完整堆栈跟踪:
Caused by: java.lang.AbstractMethodError: abstract method "java.util.concurrent.ScheduledExecutorService io.grpc.internal.ClientTransportFactory.getScheduledExecutorService()"
at io.grpc.internal.CallCredentialsApplyingTransportFactory.getScheduledExecutorService(CallCredentialsApplyingTransportFactory.java:52)
at io.grpc.internal.ManagedChannelImpl.<init>(ManagedChannelImpl.java:560)
at io.grpc.internal.AbstractManagedChannelImplBuilder.build(AbstractManagedChannelImplBuilder.java:419)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:222)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:164)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:156)
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:157)
at com.google.cloud.speech.v1.stub.GrpcSpeechStub.create(GrpcSpeechStub.java:94)
at com.google.cloud.speech.v1.stub.SpeechStubSettings.createStub(SpeechStubSettings.java:126)
at com.google.cloud.speech.v1.SpeechClient.<init>(SpeechClient.java:144)
at com.google.cloud.speech.v1.SpeechClient.create(SpeechClient.java:126)