linux.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. const SayPlatformBase = require('./base.js')
  2. const BASE_SPEED = 100
  3. const COMMAND = 'festival'
  4. class SayPlatformLinux extends SayPlatformBase {
  5. constructor () {
  6. super()
  7. this.baseSpeed = BASE_SPEED
  8. }
  9. buildSpeakCommand ({ text, voice, speed }) {
  10. let args = []
  11. let pipedData = ''
  12. let options = {}
  13. args.push('--pipe')
  14. if (speed) {
  15. pipedData += `(Parameter.set 'Audio_Command "aplay -q -c 1 -t raw -f s16 -r $(($SR*${this.convertSpeed(speed)}/100)) $FILE") `
  16. }
  17. if (voice) {
  18. pipedData += `(${voice}) `
  19. }
  20. pipedData += `(SayText "${text}")`
  21. return { command: COMMAND, args, pipedData, options }
  22. }
  23. buildExportCommand ({ text, voice, speed, filename }) {
  24. throw new Error(`say.export(): does not support platform ${this.platform}`)
  25. }
  26. runStopCommand () {
  27. // TODO: Need to ensure the following is true for all users, not just me. Danger Zone!
  28. // On my machine, original childD.pid process is completely gone. Instead there is now a
  29. // childD.pid + 1 sh process. Kill it and nothing happens. There's also a childD.pid + 2
  30. // aplay process. Kill that and the audio actually stops.
  31. process.kill(this.child.pid + 2)
  32. }
  33. getVoices () {
  34. throw new Error(`say.export(): does not support platform ${this.platform}`)
  35. }
  36. }
  37. module.exports = SayPlatformLinux