diff --git a/speech-to-text/recognize_stream.js b/speech-to-text/recognize_stream.js
index <HASH>..<HASH> 100644
--- a/speech-to-text/recognize_stream.js
+++ b/speech-to-text/recognize_stream.js
@@ -91,7 +91,7 @@ RecognizeStream.prototype.initialize = function() {
 
   // when the input stops, let the service know that we're done
   self.on('finish', function() {
-    if (self.socket) {
+    if (self.socket && self.socket._readyState === W3CWebSocket.OPEN) {
       self.socket.send(JSON.stringify(closingMessage));
     } else {
       this.once('connect', function () {
Solves an issue in ubuntu where trying to send a message on the socket while it isn't open would result in a crash.