Closed
Description
Description
I try to send mic data to from browser across my server then to google for recognition, here is the core code for data sending to google cloud api.
My data
get from a browser client, transferred by WebSocket.
const context = new AudioContext();
....//audioPromise --> micStream --> context.createMediaStreamSource(micStream)
const scriptNode = context.createScriptProcessor(4096, 1, 1); // context is AudioContext with 48000 sample rate
scriptNode.addEventListener('audioprocess', function(e) {
const floatSamples = e.inputBuffer.getChannelData(0);
const data = btoa(floatSamples);
stompClient.send('/wss/speech/transcribe', {}, data);
});
Here is server-side data logic sending data to google:
StreamingRecognizeRequest request = StreamingRecognizeRequest.newBuilder()
.setAudioContent(ByteString.copyFrom(java.util.Base64.getDecoder().decode(data)))
.build();
// Thread.sleep(2550); // without this line, i got too fast; with thread.sleep an other numbers yeild either too slow or too fast, what is optimial?
requestObserver.onNext(request);
Issues
- Audio data is being streamed too fast. Please stream audio data approximately at real time; or
- Audio data is being streamed too slow. Please stream audio data approximately at real time;
- io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Client GRPC deadline too short. Should be at least: 3 * audio-duration + 5 seconds. Current deadline is: 199.99576816754416 second(s). Required at least: 206 second(s).
Could you help me is there anything I did wrong? How can I solve these issue?