Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added flite tts engine #286

Merged
merged 1 commit into from
Jan 19, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions client/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,74 @@ def say(self, phrase):
self.play(out_f.name)


class FliteTTS(AbstractTTSEngine):
"""
Uses the flite speech synthesizer
Requires flite to be available
"""

SLUG = 'flite-tts'

def __init__(self, voice=''):
super(self.__class__, self).__init__()
self.voice = voice if voice and voice in self.get_voices() else ''

@classmethod
def get_voices(cls):
cmd = ['flite', '-lv']
voices = []
with tempfile.SpooledTemporaryFile() as out_f:
subprocess.call(cmd, stdout=out_f)
out_f.seek(0)
for line in out_f:
if line.startswith('Voices available: '):
voices.extend([x.strip() for x in line[18:].split()
if x.strip()])
return voices

@classmethod
def get_config(cls):
# FIXME: Replace this as soon as we have a config module
config = {}
# HMM dir
# Try to get hmm_dir from config
profile_path = jasperpath.config('profile.yml')
if os.path.exists(profile_path):
with open(profile_path, 'r') as f:
profile = yaml.safe_load(f)
if 'flite-tts' in profile:
if 'voice' in profile['flite-tts']:
config['voice'] = profile['flite-tts']['voice']
return config

@classmethod
def is_available(cls):
return (super(cls, cls).is_available() and
diagnose.check_executable('flite') and
len(cls.get_voices()) > 0)

def say(self, phrase):
self._logger.debug("Saying '%s' with '%s'", phrase, self.SLUG)
cmd = ['flite']
if self.voice:
cmd.extend(['-voice', self.voice])
cmd.extend(['-t', phrase])
with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as f:
fname = f.name
cmd.append(fname)
with tempfile.SpooledTemporaryFile() as out_f:
self._logger.debug('Executing %s',
' '.join([pipes.quote(arg)
for arg in cmd]))
subprocess.call(cmd, stdout=out_f, stderr=out_f)
out_f.seek(0)
output = out_f.read().strip()
if output:
self._logger.debug("Output was: '%s'", output)
self.play(fname)
os.remove(fname)


class MacOSXTTS(AbstractTTSEngine):
"""
Uses the OS X built-in 'say' command
Expand Down