Reputation: 11
I am trying to add Text-to-Speech to a ChatBot on a web browser using NodeJS, where I want to show the text and to play the speech when I get a response.
I have searched and found the following example that creates a WAV file, which works good.
// Pipe the synthesized text to a file
text_to_speech.synthesize(params).pipe(fs.createWriteStream('output.wav'));
Instead of creating a file, how can I just play the response directly on my laptop speakers?
Upvotes: 1
Views: 326
Reputation: 1
I battled with this for a while now. I was running in on my raspberry pi and was running into problems with the speaker solution.
The below worked for me.
var Sound = require('node-aplay'); var f =text_to_speech.synthesize(params).pipe(fs.createWriteStream('output.wav')); f.on('finish', function () { new Sound('output.wav').play(); console.log("Done"); });
Upvotes: 0