all-demo.js 694 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env node
  2. const say = require('../')
  3. let text = 'This is Ground Control to Major Tom This is Ground Control to Major Tom This is Ground Control to Major Tom'
  4. let voice
  5. let speed = 2.0
  6. // output some text to the console as the callback
  7. say.speak(text, voice, speed, (error) => {
  8. if (error) {
  9. // This fires when say.stop fires. Not sure if that's a good or bad thing...
  10. return console.error('Error speaking!', error)
  11. }
  12. console.log('text to speech complete')
  13. })
  14. setTimeout(() => {
  15. console.log('prematurely killing speech')
  16. say.stop((err) => {
  17. if (err) {
  18. return console.error('unable to stop speech', err)
  19. }
  20. console.log('stopped')
  21. })
  22. }, 2000)