Vijay Innamuri
Vijay Innamuri

Reputation: 4372

Google speech API throws Invalid audio channel count

Google Speech API throws Invalid audio channel count Exception for the audio recorded on a Mac machine.

I'm just using the sample application provided by 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

Does this require any special configuration?

What does this error mean?

Upvotes: 7

Views: 5858

Answers (2)

Shannon S
Shannon S

Reputation: 191

Multi-channel is now supported in Google Cloud, however I still hit this issue because I used a stereo audio file and the sample documentation does not specify the channel count (audioChannelCount). You can do this with the following, as documented in https://cloud.google.com/speech-to-text/docs/multi-channel

const config = {
  encoding: `LINEAR16`,
  languageCode: `en-US`,
  audioChannelCount: 2,
  enableSeparateRecognitionPerChannel: true,
};

Upvotes: 5

Alex Chao
Alex Chao

Reputation: 206

Audio recorded on a Mac is most likely stereo, but currently the API seems to only support 1-channel (mono) audio. From the Audio Encoding section of the docs:

Audio encoding of the data sent in the audio message. All encodings support only 1 channel (mono) audio.

The simplest solution here might be to just convert your sample to mono using something like Audacity.

Upvotes: 6

Related Questions