|
@@ -16,6 +16,7 @@ class Pico2wave(TTSModule):
|
|
|
def __init__(self, **kwargs):
|
|
|
super(Pico2wave, self).__init__(**kwargs)
|
|
|
self.samplerate = kwargs.get('samplerate', None)
|
|
|
+ self.path = kwargs.get('path', None)
|
|
|
|
|
|
def say(self, words):
|
|
|
"""
|
|
@@ -31,15 +32,19 @@ class Pico2wave(TTSModule):
|
|
|
|
|
|
.. raises:: FailToLoadSoundFile
|
|
|
"""
|
|
|
-
|
|
|
- pico2wave_exec_path = ["/usr/bin/pico2wave"]
|
|
|
+ if self.path is None:
|
|
|
+ # we try to get the path from the env
|
|
|
+ self.path = self._get_pico_path()
|
|
|
+ # if still None, we set a default value
|
|
|
+ if self.path is None:
|
|
|
+ self.path = "/usr/bin/pico2wave"
|
|
|
|
|
|
# pico2wave needs that the file path ends with .wav
|
|
|
tmp_path = self.file_path+".wav"
|
|
|
pico2wave_options = ["-l=%s" % self.language, "-w=%s" % tmp_path]
|
|
|
|
|
|
final_command = list()
|
|
|
- final_command.extend(pico2wave_exec_path)
|
|
|
+ final_command.extend([self.path])
|
|
|
final_command.extend(pico2wave_options)
|
|
|
final_command.append(self.words)
|
|
|
|
|
@@ -52,8 +57,18 @@ class Pico2wave(TTSModule):
|
|
|
if self.samplerate is not None:
|
|
|
tfm = sox.Transformer()
|
|
|
tfm.rate(samplerate=self.samplerate)
|
|
|
- tfm.build(str(tmp_path), str(tmp_path)+("tmp_name.wav"))
|
|
|
- os.rename(str(tmp_path)+("tmp_name.wav"), tmp_path)
|
|
|
+ tfm.build(str(tmp_path), str(tmp_path) + "tmp_name.wav")
|
|
|
+ os.rename(str(tmp_path) + "tmp_name.wav", tmp_path)
|
|
|
|
|
|
# remove the extension .wav
|
|
|
os.rename(tmp_path, self.file_path)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def _get_pico_path():
|
|
|
+ prog = "pico2wave"
|
|
|
+ for path in os.environ["PATH"].split(os.pathsep):
|
|
|
+ path = path.strip('"')
|
|
|
+ exe_file = os.path.join(path, prog)
|
|
|
+ if os.path.isfile(exe_file):
|
|
|
+ return exe_file
|
|
|
+ return None
|