GeezerVison is showing github.com — Audio data is being streamed too fast... Cloud Speech API Sample · Issue #1534 · googleapis/google-cloud-java
Audio data is being streamed too fast... Cloud Speech API Sample #1534Labels api: speechIssues related to the Speech-to-Text API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. DescriptionKeep getting the following error for grpc/StreamingRecognizeClient sample (a bit modified to access web-camera mike), I tried different sample rate values, but all of my attempts failed Any suggestions?
update. Error log:
ERROR - recognize failed: {0}
io.grpc.StatusRuntimeException: OUT_OF_RANGE: Audio data is being streamed too fast. Please stream audio data approximately at real time.
at io.grpc.Status.asRuntimeException(Status.java:545)
at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:395)
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.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Activitygarrettjonesgoogle commented on Jan 13, 2017 Your issue seems to be missing the actual error, could you add it? WrathOfFlame commented on Jan 14, 2017 I should have said that the exception is raised even if the input data was recognized and actual response contains transcripts with the phrases expected binhndicts commented on Jun 2, 2017 I got the same problem when trying to restart listening. Stop audio listening + streaming and start them after 2s. After the steps, the error occur continuously anthmgoogle commented on Nov 9, 2017 May be a config or code-gen issue. added type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. on Nov 9, 2017added priority: p2Moderately-important priority. Fix may not be included in next release. and removed priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release. on Dec 21, 2017pongad commented on Jan 25, 2018 I don't think either codegen or bitrate is the problem. I believe the sample is we're sending the bytes too fast.
I created a reproduction below, where I throttle the sound upload (search for "throttle"). If we comment out that line, the stream fails with the "stream too fast" error. If I leave the line there, everything seems to work as intended.
It is strange that this could be happening with a microphone though. I think there are a couple of suspects:
- Perhaps you set the sample rate in the config wrong. If the mic records at 10,000 hz and you set 5,000, the API will probably think you're sending data twice as fast as you should.
- Could there be issues will excessive buffering? Eg, we're trying to send data for many seconds as once?
Due to age, I'll close this issue for now. I think it's unlikely that it's a client problem. If the issue persists, please feel free to reopen.
public static void main(String[] args) throws Exception {
int sampleRate = 44100;
int bytesPerSample = 2;
ByteString speech =
ByteString.readFrom(
new FileInputStream("path/to/audio.flac"));
try (SpeechClient speechClient = SpeechClient.create()) {
ApiStreamObserver<StreamingRecognizeResponse> responseObserver =
new ApiStreamObserver<StreamingRecognizeResponse>() {
@Override
public void onNext(StreamingRecognizeResponse response) {
System.out.println(response);
}
@Override
public void onError(Throwable t) {
System.out.println("ERROR: " + t);
System.exit(1);
}
@Override
public void onCompleted() {
System.out.println("COMPLETED");
}
};
ApiStreamObserver<StreamingRecognizeRequest> requestObserver =
speechClient.streamingRecognizeCallable().bidiStreamingCall(responseObserver);
requestObserver.onNext(
StreamingRecognizeRequest.newBuilder()
.setStreamingConfig(
StreamingRecognitionConfig.newBuilder()
.setConfig(
RecognitionConfig.newBuilder()
.setEncoding(AudioEncoding.FLAC)
.setSampleRateHertz(sampleRate)
.setLanguageCode("en-US")
.build())
.build())
.build());
int step = sampleRate * bytesPerSample;
for (int i = 0; i < speech.size(); i += step) {
requestObserver.onNext(
StreamingRecognizeRequest.newBuilder()
.setAudioContent(speech.substring(i, Math.min(i + step, speech.size())))
.build());
Thread.sleep(1000); // throttle so we send only 1 sec of sound per sec.
}
for (; ; ) Thread.sleep(1000); // Don't let main exit, or the JVM will close.
}
}
MetadataMetadataapi: speechIssues related to the Speech-to-Text API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. DevelopmentNo branches or pull requestsIssue actions
|