Skip to content

Commit

Permalink
FlitePlugin: Lazy loading default voice path
Browse files Browse the repository at this point in the history
  • Loading branch information
furushchev committed Apr 10, 2023
1 parent c0a6bd3 commit da92647
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions sound_play/src/sound_play/flite_plugin.py
Expand Up @@ -14,10 +14,14 @@ class FlitePlugin(SoundPlayPlugin):

def __init__(self):
super(FlitePlugin, self).__init__()
self.rospack = rospkg.RosPack()
self.default_voice_path = os.path.join(
self.rospack.get_path('sound_play'),
'resources/flitevox')
self._default_voice_path = None

def get_default_voice_path(self):
if self._default_voice_path is None:
self._default_voice_path = os.path.join(
rospkg.RosPack().get_path('sound_play'),
'resources/flitevox')
return self._default_voice_path

def sound_play_say_plugin(self, text, voice):
if voice is None or voice == '':
Expand All @@ -29,7 +33,7 @@ def sound_play_say_plugin(self, text, voice):
voice = voice
else:
voice = os.path.join(
self.default_voice_path, voice)
self.get_default_voice_path(), voice)
(wavfile, wavfilename) = tempfile.mkstemp(
prefix='sound_play', suffix='.wav')
os.close(wavfile)
Expand Down

0 comments on commit da92647

Please sign in to comment.