pico2wave.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import os
  2. import subprocess
  3. from core.TTS.TTSModule import TTSModule
  4. import logging
  5. import sys
  6. logging.basicConfig()
  7. logger = logging.getLogger("kalliope")
  8. class Pico2wave(TTSModule):
  9. def __init__(self, **kwargs):
  10. super(Pico2wave, self).__init__(**kwargs)
  11. def say(self, words):
  12. self.generate_and_play(words, self._generate_audio_file)
  13. def _generate_audio_file(self):
  14. pico2wave_exec_path = ["/usr/bin/pico2wave"]
  15. # pico2wave needs that the file path ends with .wav
  16. tmp_path = self.file_path+".wav"
  17. pico2wave_options = ["-l=%s" % self.language, "-w=%s" % tmp_path]
  18. final_command = list()
  19. final_command.extend(pico2wave_exec_path)
  20. final_command.extend(pico2wave_options)
  21. final_command.append(self.words)
  22. logger.debug("Pico2wave command: %s" % final_command)
  23. # generate the file with pico2wav
  24. subprocess.call(final_command, stderr=sys.stderr)
  25. # remove the extension .wav
  26. os.rename(tmp_path, self.file_path)