I'm trying to use node-speaker to speak an Amazon polly stream, once read I'm saving into a file a cache and second time I want to read that file with the speaker.
It works well but the script is exiting with Process finished with exit code 132 (interrupted by signal 4: SIGILL)
Here is my method:
speak: (text, cacheDisabled = false) => {
const hash = path.join(__dirname, 'cache', crypto.createHash('md5').update(text).digest('hex') + '.pcm')
return new Promise((resolve, reject) => {
fs.exists(hash, exist => {
if (exist) {
const audioFile = fs.createReadStream(hash)
audioFile.pipe(this.player)
}
else {
const audioFile = fs.createWriteStream(hash)
const params = {
'Text': text,
'OutputFormat': 'pcm',
'VoiceId': this.config.voiceId
}
this.polly.synthesizeSpeech(params, (err, data) => {
if (err) {
reject(err)
}
else if (data) {
if (data.AudioStream instanceof Buffer) {
// Initiate the source
const bufferStream = new Stream.PassThrough()
// convert AudioStream into a readable stream
bufferStream.end(data.AudioStream)
// save to file
if (!cacheDisabled && !this.cacheDisabled) {
bufferStream.pipe(audioFile)
}
// Pipe into Player
bufferStream.pipe(this.player)
resolve()
}
else {
reject()
}
}
})
}
})
})
}
And my player is basic:
this.player = new Speaker({
channels: 1,
bitDepth: 16,
sampleRate: 16000
})
Any idea how to prevent that ? Very annoying because it crash the project