Google Speech API抛出无效的音频通道数Mac计算机上录制的音频的例外情况。
我刚刚使用Google提供的示例应用程序。
com.google.api.gax.grpc.ApiException: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Invalid audio channel count
at com.google.api.gax.grpc.ExceptionTransformingCallable$ExceptionTransformingFuture.onFailure(ExceptionTransformingCallable.java:109)
at com.google.api.gax.core.ApiFutures$1.onFailure(ApiFutures.java:52)
at com.google.common.util.concurrent.Futures$6.run(Futures.java:1764)
at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:456)
at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:817)
at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:753)
at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:634)
at io.grpc.stub.ClientCalls$GrpcFuture.setException(ClientCalls.java:466)
at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:442)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:481)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$600(ClientCallImpl.java:398)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:513)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:52)
at io.grpc.internal.SerializingExecutor$TaskRunner.run(SerializingExecutor.java:154)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Invalid audio channel count
at io.grpc.Status.asRuntimeException(Status.java:545)
... 13 more
这需要任何特殊配置吗?
这个错误是什么意思?
答案 0 :(得分:4)
Google Cloud现在支持多通道,但是仍然遇到此问题,因为我使用了立体声音频文件,并且示例文档未指定通道数(audioChannelCount
)。您可以按照https://cloud.google.com/speech-to-text/docs/multi-channel
const config = {
encoding: `LINEAR16`,
languageCode: `en-US`,
audioChannelCount: 2,
enableSeparateRecognitionPerChannel: true,
};
答案 1 :(得分:2)
Mac上录制的音频很可能是立体声,但目前API似乎只支持1声道(单声道)音频。来自docs的音频编码部分:
音频消息中发送的数据的音频编码。所有编码仅支持1声道(单声道)音频。
这里最简单的解决方案可能是使用Audacity等方式将您的样本转换为单声道。