Migushthe2nd / MsEdgeTTS

A simple Azure Speech Service module that uses the Microsoft Edge Read Aloud API
https://migushthe2nd.github.io/MsEdgeTTS/
MIT License
264 stars 40 forks source link

Error [ERR_STREAM_PUSH_AFTER_EOF]: stream.push() after EOF #15

Closed dzlandis closed 3 weeks ago

dzlandis commented 6 months ago

I'm working on a program which requires the generation of many TTS audio streams. In this program, I iterate through each string using a for loop and have it read using this package with the toStream function with configured ProsodyOptions. This error randomly occurs during the iteration of generating TTS audio.

Here is the full error stack:

node:events:496
      throw er; // Unhandled 'error' event
      ^

Error [ERR_STREAM_PUSH_AFTER_EOF]: stream.push() after EOF
    at readableAddChunkPushByteMode (node:internal/streams/readable:493:28)
    at Readable.push (node:internal/streams/readable:390:5)
    at MsEdgeTTS.cacheAudioData (C:\Users\me\Documents\GitHub\project\node_modules\msedge-tts\dist\MsEdgeTTS.js:166:32)
    at _ws.onmessage (C:\Users\me\Documents\GitHub\project\node_modules\msedge-tts\dist\MsEdgeTTS.js:142:30)
    at callListener (C:\Users\me\Documents\GitHub\project\node_modules\ws\lib\event-target.js:290:14)
    at WebSocket.onMessage (C:\Users\me\Documents\GitHub\project\node_modules\ws\lib\event-target.js:209:9)
    at WebSocket.emit (node:events:518:28)
    at Receiver.receiverOnMessage (C:\Users\me\Documents\GitHub\project\node_modules\ws\lib\websocket.js:1209:20)
    at Receiver.emit (node:events:518:28)
    at C:\Users\me\Documents\GitHub\project\node_modules\ws\lib\receiver.js:581:16
Emitted 'error' event on Readable instance at:
    at emitErrorNT (node:internal/streams/destroy:169:8)
    at emitErrorCloseNT (node:internal/streams/destroy:128:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  code: 'ERR_STREAM_PUSH_AFTER_EOF'
}

This error seems to be initiated by the following code:

this._queue[requestId].push(audioData);

This line is located in the cacheAudioData function. The error itself seems to have to do with pushing audioData after the stream has already ended.

If you come up with a fix, even if temporary, please let me know! If you need any additional information, please feel free to ask.

Migushthe2nd commented 6 months ago

to do with pushing audioData after the stream has already ended.

I think so too, but I wasn't able to replicate it by creating 100 simultanous streams. Would you be able to create a test case in https://github.com/Migushthe2nd/MsEdgeTTS/blob/main/src/MsEdgeTTS.spec.ts ?