ERR_STREAM_WRITE_AFTER_END when streamingDetectIntent with singleUtterance config
Hello,
When using the streamingDetectIntent method with the singleUtterance config to true, the stream will be ended after the first detected intent so the ERR_STREAM_WRITE_AFTER_END error will be triggered right after. I think it does work with no error with node v12 but not with node v14.
Environment details
- OS: macOS 10.15.7
- Node.js version: 14.15.0
- npm version: 6.14.8
@google-cloud/dialogflowversion: 3.3.0
Steps to reproduce
- Use the singleUterrance param in the initial stream request:
const initialStreamRequest = {
session: sessionPath,
queryInput: {
audioConfig: {
audioEncoding: 'AUDIO_ENCODING_MULAW',
sampleRateHertz: 8000,
languageCode: 'fr-FR',
singleUtterance: true
}
}
}
const detectStream = sessionClient.streamingDetectIntent()
detectStream.write(initialStreamRequest)
Here is the stack trace:
Error [ERR_STREAM_WRITE_AFTER_END]: write after end
at ClientHttp2Stream.Writable.write (_stream_writable.js:292:11)
at /ProjectDirectory/node_modules/@grpc/grpc-js/build/src/call-stream.js:549:34
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at runNextTicks (internal/process/task_queues.js:62:3)
at processImmediate (internal/timers.js:434:9) {
code: 'ERR_STREAM_WRITE_AFTER_END'
}
Also, I can see in the documentation and examples that the singleUtterance param is used outside of the audioConfig object but I think it should be inside of it, as mentionned in https://cloud.google.com/dialogflow/es/docs/how/detect-intent-stream (streamingDetectIntent method has a query_input.audio_config.single_utterance parameter that affects speech recognition).
I'm available if you need more information, thank you for your time.
Hi @antoineneff, thank you for using our service. I was able to run this repro with no errors.
From the docs (when singleUtterance set to true):
Recognition ceases when it detects the audio's voice has stopped or paused. In this case, once a detected intent is received, the client should close the stream and start a new request with a new stream as needed.
This would explain why you’re getting an error when you try to write additional requests to the service without having the client close the stream as needed.
Please, note:
If false (default), recognition does not cease until the client closes the stream.
If your audio input includes different "intentions" and you’re looking for the service to detect the right (the most specific) intent, then maybe you need to set your singleUtterance flag to false.
Hello @b-loved-dreamer, thank you for your answer.
I must have missed this detail in the docs.
For my use case, I need to detect intents as the audio plays, that's why I'm using the singleUtterance parameter (it automatically detects audio pauses).
Currently, I'm restarting the stream after every detected intent so everything is working fine (but I thought it was a workaround).
We can close this but I think the singleUtterance param is not in the right place in the Node.js example (https://github.com/googleapis/nodejs-dialogflow/blob/master/samples/detect.js#L286), shouldn't it be inside audioConfig object ?
I am glad you were able to make it work. I will ask the appropriate team about the singleUtterance field. In any case, please feel free to visit the documentation. Again, thank you for using our service.
For the sake of documenting, this PR fixes the "singleUtterance param is not in the right place in the Node.js example" noticed by the user in this issue ticket.