You can use say.js to speak text using the system's default voice and speed, or specify a custom voice and speed. You can also override the platform detection manually if needed.
To use the default settings:
const say = require('say')
say.speak('Hello!')
To use a specific voice and speed (where 1 is 100%, 0.5 is 50%, etc.):
say.speak("What's up, dog?", 'Alex', 0.5)
To execute a callback once the speech is finished:
say.speak("What's up, dog?", 'Good News', 1.0, (err) => {
if (err) {
return console.error(err)
}
console.log('Text has been spoken.')
});
// automatically pick platform
const say = require('say')
// or, override the platform
const Say = require('say').Say
const say = new Say('darwin' || 'win32' || 'linux')
// Use default system voice and speed
say.speak('Hello!')
// Stop the text currently being spoken
say.stop()
// More complex example (with an OS X voice) and slow speed
say.speak("What's up, dog?", 'Alex', 0.5)
// Fire a callback once the text has completed being spoken
say.speak("What's up, dog?", 'Good News', 1.0, (err) => {
if (err) {
return console.error(err)
}
console.log('Text has been spoken.')
});