evancohen / sonus

:speech_balloon: /so.nus/ STT (speech to text) for Node with offline hotword detection
MIT License
625 stars 79 forks source link

Calling Sonus.start() after Sonus.stop() crashes SnowboyDetect with a "write after end" #16

Closed arilotter closed 7 years ago

arilotter commented 7 years ago

To reproduce:

sonus = Sonus.init(.......);

Sonus.start(sonus);
Sonus.stop();
Sonus.start(sonus);
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: write after end
    at writeAfterEnd (_stream_writable.js:166:12)
    at SnowboyDetect.Writable.write (_stream_writable.js:217:5)
    at PassThrough.ondata (_stream_readable.js:555:20)
    at emitOne (events.js:96:13)
    at PassThrough.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at PassThrough.Readable.push (_stream_readable.js:134:10)
    at PassThrough.Transform.push (_stream_transform.js:128:32)
    at afterTransform (_stream_transform.js:77:12)
    at TransformState.afterTransform (_stream_transform.js:54:12)
ashishsc commented 7 years ago

Thanks for the report, we'll investigate this shortly.

evancohen commented 7 years ago

Ah, I see what's going on here. Because the Detector is a writable stream it's automatically ending when the buffer stops writing to it. Calling stream.write() after stream.end() will raise an error.

We'd be able to solve this issue by creating a new native detector instance when start is called again, but I don't think that's how it should work.

I'd be more inclined to create pause/resume to get the functionality I think you're looking for. I'll create a PR for this shortly.