googleapis / google-cloud-node

Google Cloud Client Library for Node.js
https://cloud.google.com/nodejs
Apache License 2.0
2.9k stars 589 forks source link

Google-cloud/speech emitting close event after short period of inactivity #2105

Closed shekit closed 7 years ago

shekit commented 7 years ago

Environment details

Steps to reproduce

  1. I've written an electron app that streams from the mic input to google speech on a hotword being detected which can be found in this file https://github.com/shekit/electron-voice.
  2. Clone repo - https://github.com/shekit/electron-voice
  3. npm install -g electron@1.6.2
  4. npm install --save nan
  5. HOME=~/.electron-gyp npm install in project folder
  6. Place google speech keyfile.json in project folder
  7. electron main.js (from project folder)
  8. Say 'snowboy' followed by a command

The Issue

  1. After a small period of inactivity if I speak something, I immediately receive the close event from the google detector and it doesn't transcribe anything. If I trigger it again, it transcribes successfully.
  2. I only receive this close event after a short period of inactivity which I have found to be consistently ~4 minutes, but no error is triggered.
  3. I'm explicitly calling mic.unpipe(googlestream) and googlestream.end() after I receive the final transcribed results. single_utterance is set to true.

Any idea why this would be happening? This does not seem to be a timeout error as I am listening for error events emitted by the google stream and no errors are being emitted.

Thanks!

lukesneeringer commented 7 years ago

Hi @shekit; thanks for reporting this. My understanding was that the Speech API does close the connection after some time, so this might be intended behavior. I will attempt to find out.

For what it is worth, I do think there is a pretty good case to be made for closing the connection after a few minutes of inactivity. After all, consider the case where we do not close a connection and someone inadvertently leaves one open and then gets a huge bill from us.

shekit commented 7 years ago

Hey @lukesneeringer, thanks for the response! I don't think that is the issue though. When I don't close the stream, google automatically sends me an error message around the 60 sec mark saying the maximum permissible limit is 65 seconds and closes the connection, which makes sense as it is indicated as the permissible streaming content limit in the docs.

So I began to explicitly close the google stream connection by causing .end() on it and I no longer receive that error around the 60 sec mark. However it does silently close(with no error) if I open another new connection and make a request after 4 mins.

If on the other hand, I continue making requests, as long as they are made within that 4 min mark, even if it is at 3 mins 50 seconds then I can keep it running forever.

stephenplusplus commented 7 years ago

@shekit Sorry for the delay in our investigation. Thank you for your patience. Since this issue got a bit stale, I wondered if you're still having problems or have found any solutions? I will dive in and follow the reproduction steps above, I just want to be sure you're still having these issues.